/* C version of solution 1.
 *
 * Author: Matt Eastman
 */
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define FALSE 0
#define TRUE 1

typedef struct {
  int top;
  int left;
  int bottom;
  int right;
} SubBox;

typedef struct {
  char line[1024];
  SubBox* sub_boxes[3];
} Box;

SubBox* SubBox_New(int top, int left, int bottom, int right) {
  SubBox* box = (SubBox*)calloc(1, sizeof(SubBox));
  box->top = top;
  box->left = left;
  box->bottom = bottom;
  box->right = right;
  return box;
}

int SubBox_Touches(SubBox* a, SubBox* b) {
  if (a->top >= b->bottom &&
      a->bottom <= b->top &&
      a->left <= b->right &&
      a->right >= b->left)
    return TRUE;
  return FALSE;
}

void SubBox_Del(SubBox* box) {
  free(box);
}

Box* Box_New(char* line) {
  int top, left, bottom, right, line_size;
  Box* box = (Box*)calloc(1, sizeof(Box));

  strcpy(box->line, line);
  line_size = strlen(line);
  while (line_size > 0 && isspace(box->line[line_size - 1]))
    line_size--;
  box->line[line_size] = '\0';

  assert(sscanf(line, " %d,%d %d,%d", &top, &left, &bottom, &right) == 4);
  left = (left + 180) % 360;
  right = (right + 180) % 360;

  if (left > right) {
    box->sub_boxes[0] = SubBox_New(top, left, bottom, 360);
    box->sub_boxes[1] = SubBox_New(top, 0, bottom, right);
  } else if (left == 0) {
    box->sub_boxes[0] = SubBox_New(top, 360, bottom, 360);
    box->sub_boxes[1] = SubBox_New(top, 0, bottom, right);
  } else if (right == 0) {
    box->sub_boxes[0] = SubBox_New(top, left, bottom, 360);
    box->sub_boxes[1] = SubBox_New(top, 0, bottom, 0);
  } else {
    box->sub_boxes[0] = SubBox_New(top, left, bottom, right);
  }

  return box;
}

int Box_Touches(Box* a, Box* b) {
  int i, j;
  for (i = 0; a->sub_boxes[i] != NULL; i++) {
    for (j = 0; b->sub_boxes[j] != NULL; j++) {
      if (SubBox_Touches(a->sub_boxes[i], b->sub_boxes[j]))
        return TRUE;
    }
  }
  return FALSE;
}

void Box_Del(Box* box) {
  int i;
  for (i = 0; box->sub_boxes[i] != NULL; i++) {
    SubBox_Del(box->sub_boxes[i]);
  }
  free(box);
}

Box** ReadBoxList(int* num_boxes) {
  Box** boxes;
  char buf[1024];
  int i;

  assert(scanf(" %d ", num_boxes) == 1);
  boxes = (Box**)calloc(*num_boxes, sizeof(Box*));
  for (i = 0; i < *num_boxes; i++) {
    boxes[i] = Box_New(fgets(buf, sizeof(buf), stdin));
  }
  return boxes;
}

void FreeBoxList(Box** boxes, int num_boxes) {
  int i;
  for (i = 0; i < num_boxes; i++) {
    Box_Del(boxes[i]);
  }
  free(boxes);
}

int main(int argc, char** argv) {
  int num_cases, num_data_boxes, num_query_boxes;
  int case_num, i, j, num_matched;
  Box** data_boxes;
  Box** query_boxes;

  assert(scanf(" %d", &num_cases) == 1);
  for (case_num = 0; case_num < num_cases; case_num++) {
    if (case_num > 0)
      printf("\n");

    data_boxes = ReadBoxList(&num_data_boxes);
    query_boxes = ReadBoxList(&num_query_boxes);

    num_matched = 0;
    for (i = 0; i < num_data_boxes; i++) {
      for (j = 0; j < num_query_boxes; j++) {
        if (Box_Touches(data_boxes[i], query_boxes[j])) {
          printf("%s\n", data_boxes[i]->line);
          num_matched++;
          break;
        }
      }
    }
    if (num_matched == 0)
      printf("No data found.\n");

    FreeBoxList(data_boxes, num_data_boxes);
    FreeBoxList(query_boxes, num_query_boxes);
  }
  return 0;
}
