#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
typedef struct node
{
int data;
struct node *next;
}L1,L2;
void startL1(L1 *&LA)
{
LA=(L1 *)malloc(sizeof(L1));
}
void startL2(L2 *&LB)
{
LB=(L2 *)malloc(sizeof(L2));
}
void createL1(L1 *&LA,int num1)
{
L1 *p,*q;
p=LA;
for(int i=0;i<num1;i++)
{
q=(L1 *)malloc(sizeof(L1));
cin>>q->data;
p->next=q;
p=q;
}
p->next=NULL;
}
void createL2(L2 *&LB,int num2)
{
L2 *r,*s;
r=LB;
for(int i=0;i<num2;i++)
{
s=(L2 *)malloc(sizeof(L2));
cin>>s->data;
r->next=s;
r=s;
}
r->next=NULL;
}
void disp(L1 *&LA,int num1,L2 *&LB,int num2)
{
L1 *temp1=LA->next;
L2 *temp2=LB->next;
int flag=0;
for(int i=0;i<num1;i++)
{
temp2=LB->next;
flag=0;
for(int j=0;j<num2;j++)
{
if(temp1->data==temp2->data)
{
cout<<temp1->data<<" ";
flag=1;
temp1=temp1->next;
break;
}
temp2=temp2->next;
}
if(flag==0) temp1=temp1->next;
}
}
int main()
{
int num1,num2;
cin>>num1;
L1 *LA;
L2 *LB;
startL1(LA);
createL1(LA,num1);
cin>>num2;
startL2(LB);
createL2(LB,num2);
disp(LA,num1,LB,num2);
return 0;
}