#include <iostream>
#include <map>
#include <vector>
using namespace std;
struct student {
    int no;
    string name;
    string sex;
    int age;
};
int main() {
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        int m; cin >> m;
        map<int, student>Map;
        for (int j = 0; j < m; ++j) {
            student s;
            cin >> s.no >> s.name >> s.sex >> s.age;
            Map[s.no] = s;
        }
        cin >> m;
        student temp = Map[m];
        cout << temp.no << " " << temp.name << " " << temp.sex << " " << temp.age << endl;
    }
}
// 64 位输出请用 printf("%lld")

中文占多个字符,所以性别不能用一个char