#include<iostream>
#include<list>
#include<algorithm>
using namespace std;
int n, k, p, m, x;
bool vis[100001];
list<int> v;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
v.push_front(1);
for (int i = 2, j = 1; j < n; i++, j++) {
cin >> k >> p;
if (v.size() == 1) {
if (!p)v.push_front(i);
else v.push_back(i);
}
else if (p) {
list<int>::iterator it = v.begin();
for (; *it != k; it++);
it++;
v.insert(it, i);
}
else {
list<int>::iterator it = v.begin();
for (; *it != k; it++);
v.insert(it, i);
}
}
cin >> m;
for (int i = 1; i <= m; i++) {
cin >> x;
list<int>::iterator it = v.begin();
if (!vis[x]) {
for (; *it != x; it++);
v.erase(it);
vis[x] = 1;
}
else continue;
}
for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
cout << *it << " ";
}
return 0;
}