#include <iostream>
#include <algorithm>
#define MAX 21
using namespace std;

typedef struct{
	int no;
	string name;
	string gender;
	int age;
}stu;
 
int main(){
	stu data[MAX];
	int m,n,no;
	cin>>m;
	while(m--){
		cin>>n;
		for(int i = 0; i < n; i++){
			cin>>data[i].no>> data[i].name>>data[i].gender>>data[i].age;
		}
		cin>>no;
		for(int i = 0; i < n; i++){
			if(data[i].no == no){
				cout<<data[i].no<<" "<<data[i].name<<" "<<data[i].gender<<" "<<data[i].age<<endl;
			}
		}
	}

}