1 #include<iostream>
2 #include<string>
3 using namespace std;
4 int origin_top;
5 int target_top;
6 void Delete(string array[],int index)
7 {
8 while(origin_top!=index)
9 {
10 array[index]=array[index-1];
11 index--;
12 }
13 origin_top++;
14 }
15 int main()
16 {
17 int k;
18 while(cin>>k)
19 {
20 getchar();
21 for(int Case=0;Case<k;Case++)
22 {
23 int n;
24 cin>>n;
25 getchar();
26 string origin[200],target[200];
27 int i;
28 for(i=0;i<n;i++)
29 getline(cin,origin[i]);
30 origin_top=0;
31 for(i=0;i<n;i++)
32 getline(cin,target[i]);
33 target_top=0;
34 i=n-1;
35 int j=n-1;
36 while(i>=origin_top)
37 {
38 if(origin[i]==target[j])
39 {
40 i--;
41 j--;
42 }
43 else
44 Delete(origin,i);
45 }
46 for(i=origin_top-1;i>=0;i--)
47 cout<<target[i]<<endl;
48 cout<<endl;
49 }
50 }
51 return 0;
52 }