#include<iostream>
using namespace std;
struct srt{
int pre;
int here;
int next;
};
srt list[100010];
int main(){
int n;
cin >> n;
list[1].here = 1;
list[1].pre = 0;
list[1].next = 2;
int y = 1;
for(int i = 2;i <= n;i++){
int x,turn;
cin >> x >> turn;
list[i].here = i;
if(turn == 0){
list[i].pre = list[x].pre;
list[list[x].pre].next = i;
list[i].next = x;
list[x].pre = i;
if(x == y) y = i;
}
else{
list[list[x].next].pre = i;
list[i].next = list[x].next;
list[i].pre = x;
list[x].next = i;
}
}
int m;
cin >> m;
for(int i = 0;i < m;i++){
int x;
cin >> x;
if(list[x].here){
list[x].here = 0;
n--;
list[list[x].pre].next = list[x].next;
list[list[x].next].pre = list[x].pre;
if(x == y) y = list[x].next;
}
}
while(n > 0){
cout << list[y].here <<' ';
y = list[list[y].here].next;
n--;
}
return 0;
}