1 #!/usr/bin/env python
    2 
    3 
    4 class SubBox(object):
    5   def __init__(self, top, left, bottom, right):
    6     self._top = top
    7     self._left = left
    8     self._bottom = bottom
    9     self._right = right
   10 
   11   def Touches(self, other):
   12     return (
   13         self._top >= other._bottom and
   14         self._bottom <= other._top and
   15         self._left <= other._right and
   16         self._right >= other._left)
   17 
   18 
   19 class Box(object):
   20   def __init__(self, line):
   21     self._line = line
   22     coords = [map(int, coord.split(',')) for coord in line.split()]
   23     (self._top, self._left), (self._bottom, self._right) = coords
   24     assert -90 <= self._top <= 90, (self._top, str(self))
   25     assert -90 <= self._bottom <= 90, (self._bottom, str(self))
   26     assert -180 <= self._left <= 180, (self._left, str(self))
   27     assert -180 <= self._right <= 180, (self._right, str(self))
   28     self._left = (self._left + 180) % 360
   29     self._right = (self._right + 180) % 360
   30     assert self._top >= self._bottom, (self._top, self._bottom, str(self))
   31 
   32     self._sub_boxes = []
   33     if self._left > self._right:
   34       self._sub_boxes.append(SubBox(self._top, self._left, self._bottom, 360))
   35       self._sub_boxes.append(SubBox(self._top, 0, self._bottom, self._right))
   36     elif self._left == 0:
   37       self._sub_boxes.append(SubBox(self._top, 360, self._bottom, 360))
   38       self._sub_boxes.append(SubBox(self._top, 0, self._bottom, self._right))
   39     elif self._right == 0:
   40       self._sub_boxes.append(SubBox(self._top, self._left, self._bottom, 360))
   41       self._sub_boxes.append(SubBox(self._top, 0, self._bottom, 0))
   42     else:
   43       self._sub_boxes.append(SubBox(self._top, self._left, self._bottom, self._right))
   44 
   45   def Touches(self, other):
   46     for self_sb in self._sub_boxes:
   47       for other_sb in other._sub_boxes:
   48         if self_sb.Touches(other_sb):
   49           return True
   50     return False
   51 
   52   def __str__(self):
   53     return self._line
   54 
   55 
   56 def main():
   57   for case_num in xrange(input()):
   58     if case_num:
   59       print
   60 
   61     data_boxes = []
   62     query_boxes = []
   63     for _ in xrange(input()):
   64       data_boxes.append(Box(raw_input().strip()))
   65     for _ in xrange(input()):
   66       query_boxes.append(Box(raw_input().strip()))
   67 
   68     numMatched=0
   69     for data_box in data_boxes:
   70       for query_box in query_boxes:
   71         if data_box.Touches(query_box):
   72           print data_box
   73           numMatched+=1
   74           break
   75 
   76     if  0 == numMatched:
   77         print "No data found."
   78 
   79 
   80 if __name__ == '__main__':
   81   main()