//源代码:
//cheese.c
#include<stdio.h>
#include<math.h>
#include<stdlib.h>typedef struct bubble {
int claw;
int z;
int x;
int y;
struct bubble *last;
struct bubble *next;
}BUB;int search();
int start();
int delline();
int h, r;
BUB *head;int main() {
int i,j;
int T;
FILE *fin,*fout; fin=fopen("cheese.in","r");
fout = fopen("cheese.out", "w"); fscanf(fin,"%d",&T);
for (i = 0; i < T; i++) {
int n;
head = NULL;
fscanf(fin,"%d%d%d",&n,&h,&r);
BUB *newbub,*r,*l;
newbub = NULL; l= NULL; r = NULL;
for (j = 0; j < n; j++) {
int x, y, z;
fscanf(fin, "%d%d%d", &x, &y, &z);
newbub = (BUB*)malloc(sizeof(BUB));
newbub->next = NULL;
newbub->last = NULL;
newbub->claw = 1;
newbub->x = x;
newbub->y = y;
newbub->z = z;
if (head == NULL) {
head = newbub;
r = newbub;
//newbub->next = l;
}
else {
int bo = 1;
//int s;
while (bo) {
if (r==NULL|| l == NULL||newbub->z > r->z&&newbub->z < l->z ) {
newbub->last = r;
if(r!=NULL)r->next = newbub;
if(l!=NULL)l->last = newbub;
newbub->next = l;
r = newbub;
//newbub->next = l;
//l = newbub->next;
bo = 0;
continue;
}
if (newbub->z < r->z) {
l = r;
r = r->last;
continue;
}
if (newbub->z > l->z) {
r =l;
l = l->next;
continue;
}
}
}
/*if (head == NULL) {
head = newbub;
r = newbub;
}
else {
newbub->last = r;
r->next = newbub;
r = newbub;
}*/
}
if (start()) {
fprintf(fout,"YES\n");
}
else {
fprintf(fout, "NO\n");
}
delline();
}
fclose(fin);
fclose(fout);
return 0;
}
int start() {
BUB *p;
p = head;
while (1) {
if (p->z >= r) return 0;
if (search(p)) return 1;
else p = p->next;
}
}
int search(BUB *p) {
if (p->z >= h - r)return 1;
BUB *a;
double d;
a = p->next;
while (a->z - p->z <= r) {
if (a->claw) {
a->claw = 0;
d = sqrt(pow(p->x - a->x, 2) + pow(p->y - a->y, 2) + pow(p->z - a->z, 2));
if (d <= r)
if (search(a))return 1;
}
if (a->next == NULL)break;
else a = a->next;
}
a = p->last;
while (p->z - a->z <= r) {
if (a->claw) {
a->claw = 0;
d = sqrt(pow(p->x - a->x, 2) + pow(p->y - a->y, 2) + pow(p->z - a->z, 2));
if (d <= r)
if (search(a))return 1;
}
if (a->last == NULL)break;
else a = a->last;
}
return 0;
}
int delline() {
BUB *p,*l;
p = head;
head = NULL;
while (p != NULL) {
l = p;
p = p->next;
free(l);
}
return 0;
}