#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
int left[n+1];
int right[n+1] ;
memset(left, -1, sizeof(left));
memset(right, -1, sizeof(right));
int state[n + 1] = {0};
state[1] = 1;
left[1] = 0;
int head = 1;
for (int i = 2; i <= n; i++)
{
int t, p;
cin >> t >> p;
if (p == 0)
{
int temp = left[t];
state[i] = 1;
if (temp == 0)
{
head = i;
}
left[t] = i;
left[i] = temp;
right[i] = t;
right[temp]=i;
}
else if (p == 1)
{
state[i] = 1;
int temp2 = right[t];
right[t] = i;
right[i] = temp2;
left[i] = t;
left[temp2]=i;
}
}
int cnt = 0;
int m;
cin>>m;
for (int i = 0; i < m; i++)
{
int d;
cin >> d;
if (state[d] == 0)
{
continue;
}
else
{
cnt++;
int lechild = left[d];
int rightchild = right[d];
left[d] = right[d] = -1;
if(lechild!=-1)
right[lechild] = rightchild;
if(rightchild!=-1)
left[rightchild] = lechild;
if (left[rightchild] == 0)
{
head = rightchild;
}
}
}
int sum = 0;
while (head!=-1)
{
cout<<head<<" ";
head = right[head];
}
return 0;
}