#include
#include
char people[101][21];
int main()
{
int T,n,i;
char str[21];
scanf("%d",&T);
while(T-->0)
{
scanf("%d",&n);
getchar();
scanf("%s",str);
for(i=1;i<=n;i++)
scanf("%s",people[i]);
for(i=1;i<=n;i++)
if(strcmp(str,people[i])==0)
{
break;
}
if(i<=n/2)
printf("%s\n",people[n/2+i]);
else
printf("%s\n",people[i-n/2]);
}
return 0;
}