#include <stdio.h>
#include <stdlib.h>;
typedef struct Stu {
int data;
struct Stu* next;
}stu;
int n;
int m;
int count=0;
int left;
void create(stu** head);
void print(stu* head);
void delete(stu** head);
int main() {
scanf("%d", &n);
stu* head;
head = (stu*)malloc(sizeof(stu));
head->next = NULL;
head->data = 0;
create(&head);
delete(&head);
left = n - m;
print(head);
printf("\n");
return 0;
}
void create(stu **head) {
stu* new;
stu* p;
new = (stu*)malloc(sizeof(stu));
new->next = NULL;
new->data = 1;
(*head)->next = new;
for (int i = 2; i <= n; i++) {
p = *head;
int num;
new = (stu*)malloc(sizeof(stu));
new->next = NULL;
new->data = i;
scanf("%d", &num);
int flag;
scanf("%d", &flag);
if (flag == 0) {
while (p ->next->data!=num) {
p = p->next;
}
new->next = p->next;
p->next = new;
}
else if (flag == 1) {
while (p->data != num) {
p = p->next;
}
new->next = p->next;
p->next = new;
}
}
}
void delete(stu **head) {
int a[200000]={0};
stu* front;
front = (stu*)malloc(sizeof(stu));
front = head;
scanf("%d", &m);
for (int i = 1; i <= m; i++) {
stu* now;
now = (stu*)malloc(sizeof(stu));
now = (*head)->next;
int number;
scanf("%d", &number);
if (a[number - 1] == 0) {
int flag = 1;
while (now->data != number) {
front = now;
now = now->next;
if (now == NULL) {
flag = 0;
break;
}
}
if (flag == 1) {
front->next = now->next;
a[number - 1] = 1;
free(now);
}
}
}
}
void print(stu* head) {
stu* q;
q = head;
while (q != NULL) {
q = q->next;
if (q) { printf("%d", q->data);
if (count != left) printf(" ");
count++;
}
}
}