#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e18;
const double PI = acos(-1);

bool epsleq(const double &a, const double &b){
    return a +EPS < b;
}
bool epseq(const double &a, const double &b){
    return abs(a-b) < EPS;
}

struct Point{
    double x,y,z;
    Point(double x, double y, double z):x(x), y(y), z(z){}
    Point(){}
    Point &operator +=(const Point &a){ x+=a.x; y+=a.y; z+=a.z; return *this; }
    Point &operator -=(const Point &a){ x-=a.x; y-=a.y; z-=a.z; return *this; }
    Point &operator *=(const double &a){ x*=a; y*=a; z*=a; return *this; }
    Point operator +(const Point &a) const{ return Point(x+a.x, y+a.y, z+a.z); }
    Point operator -(const Point &a) const{ return Point(x-a.x, y-a.y, z-a.z); }
    Point operator *(const double &a) const{ return Point(a*x, a*y, a*z); }
    Point operator -() { return Point(-x, -y, -z); }
    bool operator <(const Point &a) const{
        return !epseq(x, a.x)? x < a.x: !epseq(y, a.y)? y < a.y: epsleq(z, a.z);
    }
    bool operator ==(const Point &a) const{
        double dx=x-a.x, dy=y-a.y, dz=z-a.z;
        return sqrt(dx*dx +dy*dy +dz*dz) < EPS;
    }
};

double dot(const Point &a, const Point &b){
    return a.x*b.x +a.y*b.y +a.z*b.z;
}
Point cross(const Point &a, const Point &b){
    return Point(a.y*b.z -a.z*b.y, a.z*b.x -a.x*b.z, a.x*b.y -a.y*b.x);
}
double abs(const Point &a){
    return sqrt(dot(a, a));
}
Point unit(const Point &a){
    return a *(1/abs(a));
}

Point rotate(const Point &p, const Point &axis, double angle){
    Point n = unit(axis);
    double SIN = sin(angle), COS = cos(angle);
    double vec[3] = {p.x, p.y, p.z};
    double mat[3][3] = {{COS +n.x*n.x*(1-COS), n.x*n.y*(1-COS) -n.z*SIN, n.x*n.z*(1-COS) +n.y*SIN},
                        {n.x*n.y*(1-COS) +n.z*SIN, COS +n.y*n.y*(1-COS), n.y*n.z*(1-COS) -n.x*SIN},
                        {n.x*n.z*(1-COS) -n.y*SIN, n.y*n.z*(1-COS) +n.x*SIN, COS +n.z*n.z*(1-COS)}};
    double ret[3] = {};
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            ret[i] += mat[i][j] *vec[j];
        }
    }
    return Point(ret[0], ret[1], ret[2]);
}

int md[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main(){
    int ds;
    cin >> ds;
    for(int rep=0; rep<ds; rep++){
        int mon,day,hh,mm;
        scanf("%d/%d %d:%d", &mon, &day, &hh, &mm);
        for(int i=0; i<mon-1; i++){
            day += md[i];
        }
        mm += 60 *(24*(day-1) +hh);
        
        double angle = (1+1/365.24)*360 *mm/24/60 *PI/180;

        vector<string> ans;
        Point pole(cos(43.2/180*PI), 0, sin(43.2/180*PI));
        int n;
        cin >> n;
        for(int i=0; i<n; i++){
            string name;
            int size;
            cin >> name >> size;
            bool canlook = true;
            for(int j=0; j<size; j++){
                double theta, phi;
                cin >> theta >> phi;
                theta *= PI/180;
                phi *= PI/180;
                Point p(cos(theta)*cos(phi), sin(theta)*cos(phi), sin(phi));
                p = rotate(p, pole, angle);
                if(p.z < 0){
                    canlook = false;
                }
            }
            if(canlook){
                ans.push_back(name);
            }
        }
        for(string s: ans){
            cout << s << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3736