#include <iostream>

using namespace std;

struct Student {
	int id;
	string name;
	string sex;
	int age;
};

Student stu[21];

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