#include<bits/stdc++.h>
using namespace std;
queue<int>q[2];
int n,m;
int main(){
scanf("%d",&n);
q[1].push(1);
for (int i = 2;i <= n;++i){
int x,y;
scanf("%d%d",&x,&y);
if (y == 0){
while (q[1].front() != x){
q[2].push(q[1].front());
q[1].pop();
}
q[2].push(i);
while (!q[1].empty()){
q[2].push(q[1].front());
q[1].pop();
}
while (!q[2].empty()){
q[1].push(q[2].front());
q[2].pop();
}
}
if (y == 1){
while (q[1].front() != x){
q[2].push(q[1].front());
q[1].pop();
}
q[2].push(x);
q[1].pop();
q[2].push(i);
while (!q[1].empty()){
q[2].push(q[1].front());
q[1].pop();
}
while (!q[2].empty()){
q[1].push(q[2].front());
q[2].pop();
}
}
}
int k;
scanf("%d",&k);
for (int i = 1;i <= k;++i){
int x;
scanf("%d",&x);
while (x != q[1].front() && !q[1].empty()){
q[2].push(q[1].front());
q[1].pop();
}
if (!q[1].empty()){
q[1].pop();
while (!q[1].empty()){
q[2].push(q[1].front());
q[1].pop();
}
}
while (!q[2].empty()){
q[1].push(q[2].front());
q[2].pop();
}
}
while (!q[1].empty()){
printf("%d ",q[1].front());
q[1].pop();
}
printf("\n");
return 0;
}