#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
map<int, int>m;
const int maxn = 10001;
int a[maxn];
set<int>sss;
int main()
{
int n, temp1, temp2;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> temp1 >> temp2;
m[temp1] = temp2;
m[temp2] = temp1;
}
int j;
cin >> j;
for (int i = 0; i < j; i++)
{
cin >> a[i];
}
for (int i = 0; i < j; i++)
{
int *ans=find(a, a + j, m[a[i]]);
if (ans == a + j)
{
sss.insert(a[i]);
}
}
cout << sss.size() << endl;
for (auto it = sss.begin(); it != sss.end(); it++)
{
if (it != sss.begin())
cout << " ";
printf("%05d", *it);
}
}