#include<stdio.h>
struct one{
int i;
struct one *next;
}a[100005], b, *head;
head = &b; b.i = -1; b.next = &a[0]; a[0].next = NULL;
struct one *search(struct one *h, int key, struct one **pp){
struct one *v = h, *u = NULL;
while(v!= NULL){
if(v->i==key)break;
u=v;
v=v->next;
}
*pp = u;
return v;
};
void two(struct one **hpt, int key){
struct one *u, *w;
u = *hpt;
while(u!= NULL){
if(u-> i == key)break;
w = u;
u = u-> next;
}
if(u!= NULL){
w-> next = u-> next;
u-> next = NULL;
}
return;
}
int main(){
int N;
scanf("%d", &N);
for(int i = 0; i < N; i++){
a[i].i = i+1;
if(i == 0)continue;
int k, p;
scanf("%d%d", &k, &p);
struct one *pp, *ip;
ip = search(head, k, &pp);
if(p == 0){a[i].next = pp-> next; pp-> next = &a[i]; }
else {a[i].next = ip-> next; ip-> next = &a[i]; }
}
int M;
scanf("%d", &M);
for(int j = 1; j <= M; j++){
int c;
scanf("%d", &c);
two(&head, c);
}
struct one *kp = head-> next;
while(kp!= NULL){
printf("%4d", kp-> i);
kp = kp-> next;
}
printf("\n");
return 0;
}