#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
int n, m;
struct Node {
Node * left = NULL;
Node * right = NULL;
int index;
bool isDeleted = false;
} nodes [N];
void Insert (int index, Node * Should, int angle) {
nodes [index]. index = index;
if (angle == 1) {
nodes [index]. left = Should;
nodes [index]. right = Should -> right;
if (Should -> right != NULL) Should -> right -> left = &nodes [index];
Should -> right = &nodes [index];
} else {
nodes [index]. left = Should -> left;
nodes [index]. right = Should;
if (Should -> left != NULL) Should -> left -> right = &nodes [index];
Should -> left = &nodes [index];
}
}
void Delete (Node * Deleter) {
if (Deleter -> isDeleted) return ;
Deleter -> isDeleted = true;
Node * left = Deleter -> left;
Node * right = Deleter -> right;
left -> right = right;
right -> left = left;
}
void Print (Node * root, bool flag = false, int start = -1) {
if (root != NULL && root -> index != start) {
cout << root -> index << " ";
if (flag)
Print (root -> right, false, root -> index);
else
Print (root -> right, false, start);
}
}
int main() {
cin >> n;
Insert (0, &nodes [1], 0);
Insert (1, &nodes [0], 1);
for (int i = 2; i <= n ; i ++) {
int k, p;
cin >> k >> p;
Insert (i, &nodes [k], p);
}
cin >> m;
for (int i = 1; i <= m ; i ++) {
int x;
cin >> x;
Delete (&nodes [x]);
}
Print ((&nodes [0]) -> right, true);
return 0;
}