#include <iostream>
#include <string>
using namespace std;

typedef struct {
    int id;
    string name;
    string gender;
    int age;
} Student;

int main() {
    int m, n;
    cin >> m;
    while (m--) {
        cin >> n;
        Student stu[n];
        for (int i = 0; i < n; i++) {
            cin >> stu[i].id >> stu[i].name >> stu[i].gender >> stu[i].age;
        }
        int t;
        cin >> t;
        for (int i = 0; i < n; i++) {
            if (t == stu[i].id) {
                cout << stu[i].id << " " << stu[i].name << " " << stu[i].gender << " " <<
                     stu[i].age << endl;
            }
        }
    }
}