#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_M = 1000;

const double NP_DEG = 43.2;
const double RDPM = (1.0 + 1.0 / 365.24) * 360 / (24 * 60);

const double PI = acos(-1.0);
const double DELTA = sin(0.01 * PI / 180);

const int mdays[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

/* typedef */

template <typename T>
struct Pt3D {
  T x, y, z;

  Pt3D() {}
  Pt3D(T _x, T _y, T _z) { x = _x; y = _y; z = _z; }

  bool operator==(const Pt3D<T>& pt) const {
    return x == pt.x && y == pt.y && z == pt.z;
  }

  bool operator<(const Pt3D<T>& pt) const {
    return x < pt.x || (x == pt.x && (y < pt.y || (y == pt.y && z < pt.z)));
  }
  
  Pt3D<T> operator+(const Pt3D<T>& pt) const {
    return Pt3D<T>(x + pt.x, y + pt.y, z + pt.z);
  }

  Pt3D<T> operator-(const Pt3D<T>& pt) const {
    return Pt3D<T>(x - pt.x, y - pt.y, z - pt.z);
  }
  
  Pt3D<T> operator-() const { return Pt3D<T>(-x, -y, -z); }
  Pt3D<T> operator*(const T& t) const { return Pt3D<T>(x * t, y * t, z * t); }
  Pt3D<T> operator/(const T& t) const { return Pt3D<T>(x / t, y / t, z / t); }

  T dot(const Pt3D<T>& v) const { return x * v.x + y * v.y + z * v.z; }

  Pt3D<T> cross(const Pt3D<T>& v) const {
    return Pt3D<T>(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
  }

  T d2() const { return x * x + y * y + z * z; }
  double d() const { return sqrt(d2()); }
  Pt3D<T> normalize() const { return *this / d(); }

  Pt3D<T> rotx(double th) {
    double c = cos(th), s = sin(th);
    return Pt3D<T>(x, c * y - s * z, s * y + c * z);
  }
  
  Pt3D<T> roty(double th) {
    double c = cos(th), s = sin(th);
    return Pt3D<T>(s * z + c * x, y, c * z - s * x);
  }
  
  Pt3D<T> rotz(double th) {
    double c = cos(th), s = sin(th);
    return Pt3D<T>(c * x - s * y, s * x + c * y, z);
  }
  
  void print(string format) {
    printf(("(" + format + ", " + format + ", " + format + ")\n").c_str(),
           x, y, z);
  }
  void print() { print("%.6lf"); }
};

typedef Pt3D<double> pt3d;

/* global variables */

/* subroutines */

int datetime2min(string md, string hm) {
  int m = 0, d = 0, pos = 0;

  while (md[pos] != '/') m = m * 10 + (md[pos++] - '0');
  pos++;
  while (pos < md.length()) d = d * 10 + (md[pos++] - '0');

  int hh = (hm[0] - '0') * 10 + (hm[1] - '0');
  int mm = (hm[3] - '0') * 10 + (hm[4] - '0');
  //printf("%d/%d %02d:%02d\n", m, d, hh, mm);

  int doy = d;
  for (int i = 2; i <= m; i++) doy += mdays[i - 2];
  
  return (((doy - 1) * 24) + hh) * 60 + mm;
}

/* main */

int main() {
  double dth = PI * (90.0 - NP_DEG) / 180;

  int tn;
  cin >> tn;

  while (tn--) {
    string md, hm;
    cin >> md >> hm;

    int min = datetime2min(md, hm);
    double dphi = -PI * RDPM / 180 * min;
    
    int n, m;
    string name;
    cin >> n;

    while (n--) {
      cin >> name >> m;

      bool ok = true;

      while (m--) {
	double d0, d1;
	cin >> d0 >> d1;

	if (ok) {
	  double phi = (90.0 - d0) * PI / 180;
	  double th = d1 * PI / 180;

	  double cp = cos(phi), sp = sin(phi);
	  double ct = cos(th), st = sin(th);

	  pt3d p0(cp * ct, sp * ct, st);
	  pt3d p1 = p0.rotx(dth).rotz(dphi).rotx(-dth);

	  if (p1.z <= DELTA) ok = false;
	  //cout << name << ": ";p1.print();
	}
      }

      if (ok) cout << name << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1244