#include<iostream>
#include<cmath>
#include<complex>
#include<iomanip>
#include<cassert>
#include<vector>
#include<ctime>
#include<string>
#include<cstdio>
 
using namespace std;
 
enum CCW{FRONT=0x01,RIGHT=0x02,BACK=0x04,LEFT=0x08,OVER=0x10};
typedef double elem;
typedef complex<elem> point2, vec2;
typedef pair<point2,point2> line2, seg2;
 
const elem eps = 1e-5;
const elem pi = 2*acos(0);
const elem infty = 1e50;

struct point3{
  elem x,y,z;
  point3(){}
  point3(elem x, elem y, elem z):x(x),y(y),z(z){}
  point3 operator+(const point3 &d)const{
    return point3(x+d.x,y+d.y,z+d.z);
  }
  point3 operator-(const point3 &d)const{
    return point3(x-d.x,y-d.y,z-d.z);
  }
  point3 operator*(elem d)const{
    return point3(x*d,y*d,z*d);
  }
  elem len()const{
    return sqrt(x*x + y*y + z*z);
  }
  point3 unit()const{
    double n = this->len();
    return point3(x/n,y/n,z/n);
  }
  elem dot(const point3 &d)const{
    return x*d.x + y*d.y + z*d.z;
  }
  point3 cross(const point3& d)const{
    return point3(y*d.z-z*d.y,z*d.x-x*d.z,x*d.y-y*d.x);
  }
  point3 rot(const point3 &u, double theta)
  {
    double cs = cos(theta);
    double ss = sin(theta);
    double r11 = cs + u.x * u.x * (1-cs);
    double r12 = u.x * u.y * (1-cs) - u.z * ss;
    double r13 = u.x * u.z * (1-cs) + u.y * ss;
    double r21 = u.y * u.x * (1-cs) + u.z * ss;
    double r22 = cs + u.y * u.y * (1-cs);
    double r23 = u.y * u.z * (1-cs) - u.x * ss;
    double r31 = u.z * u.x * (1-cs) - u.y * ss;
    double r32 = u.z * u.y * (1-cs) + u.x * ss;
    double r33 = cs + u.z * u.z * (1-cs);

    point3 ret;
    ret.x = r11 * x + r12 * y + r13 * z;
    ret.y = r21 * x + r22 * y + r23 * z;
    ret.z = r31 * x + r32 * y + r33 * z;
    return ret;
  }
};

struct Stella{
  string name;
  vector<point3> v;
  void rot(const point3 &u, double theta){
    //cout << name << endl;
    for(int i = 0; i < (int)v.size(); ++i){
      point3 t = v[i].rot(u,theta);
      //cout << t.x << ' ' << t.y << ' ' << t.z << endl;
      v[i] = v[i].rot(u,theta);
    }
  }
  bool visible()const{
    for(int i = 0; i < (int)v.size(); ++i){
      if( v[i].z < 0 ) return false;
    }
    return true;
  }
};

double deg2rad(double deg){return deg/180.0 * pi;}
point2 rot(point2 p, elem theta){ return p * polar((elem)1.0, theta); }
point3 conv(double l,double r)
{
  l = deg2rad(l);
  r = deg2rad(r);
  point3 t(0,1,0); // 0,0
  point3 ret = t.rot(point3(0,0,1),deg2rad(360-l));
  //point3 ret = t.rot(point3(0,0,1),deg2rad(l));
  ret = ret.rot(point3(1,0,0),deg2rad(r));
  return point3(sin(l)*cos(r),sin(l)*sin(r),cos(l));
  //return ret;
}

const double unit24 = (1+1./365.24)*360;

int main()
{
  int T;
  cin >> T;
  for(int tc=1;tc<=T;++tc){
    int mon,day,h,m;
    char dam;
    struct tm time_base;
    struct tm time_cur;
    point3 pole = conv(90-43.2,90);
    
    time_base.tm_year = 2012 - 1900;
    time_base.tm_mon = 1 - 1;
    time_base.tm_mday = 1;
    time_base.tm_hour = 0;
    time_base.tm_min = 0;
    time_base.tm_sec = 0;
    time_base.tm_isdst = -1;
    
    cin >> mon >> dam >> day >> h >> dam >> m;
    // cout << mon << ' ' << day << ' ' << h << ' ' << m << endl;

    time_cur.tm_year = 2012 - 1900;
    time_cur.tm_mon = mon - 1;
    time_cur.tm_mday = day;
    time_cur.tm_hour = h;
    time_cur.tm_min = m;
    time_cur.tm_sec = 0;
    time_cur.tm_isdst = -1;
    
    time_t base1 = mktime(&time_base);
    time_t cur1 = mktime(&time_cur);
    
    double elapsed_days = (cur1-base1)/(3600.*24);
    // cout << elapsed_days << endl;
    
    int n;
    cin >> n;
    vector< Stella > vs;
    for(int i = 0; i < n; ++i){
      Stella s;
      int k;
      cin >> s.name >> k;
      for(int j = 0; j < k; ++j){
        double l,r;
        cin >> l >> r;
        s.v.push_back(conv(90-r,90-l));
      }
      vs.push_back(s);
    }

    //cout << vs.size() << endl;
    double degree = (unit24) * elapsed_days;
    // while(degree>360)degree -= 360;
    for(int i = 0; i < (int)vs.size(); ++i){
      vs[i].rot( pole, -deg2rad(degree) );
    }
    for(int i = 0; i < (int)vs.size(); ++i){
      if( vs[i].visible() ){
        cout << vs[i].name << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1100