#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<queue>
#include<list>
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
#define mmt(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define mp make_pair
#define y1 fuck
#define N 1510010
using namespace std;
typedef long long LL;
typedef long double LD;
int siz[N],sum[N],son[N],br[N][3],n,q,top[N],Pos[N],fa[N],len[N],now[N],root[N];
vector<int> li[N];
int csiz(int x)
{
siz[x]=1;
if (x>n) return sum[x]>1;
for(int i=0;i<3;i++)
{
sum[x]+=csiz(br[x][i]);
siz[x]+=siz[br[x][i]];
if (!son[x]) son[x]=br[x][i];
else if (siz[br[x][i]]>siz[son[x]]) son[x]=br[x][i];
}
return sum[x]>1;
}
void divide(int x,bool isws)
{
if (!isws) top[x]=x;else top[x]=top[fa[x]];
Pos[x]=++len[top[x]];li[top[x]].pb(x);
if (!son[x]) return;
divide(son[x],1);
for(int i=0;i<3;i++)
{
if (br[x][i]!=son[x]) divide(br[x][i],0);
}
}
struct segnode
{
int r1max,r2max,va;
void clr(){r1max=r2max=0;}
};
struct segtree
{
segnode v[2*N];int l[2*N],r[2*N],lc[2*N],rc[2*N],lazy[2*N];
int size;
void build(int x,int L,int R)
{
int mid=(L+R)>>1;l[x]=L;r[x]=R;
if (L==R)
{
v[x].va=now[L];
if (now[L]==1) v[x].r1max=1;
if (now[L]==2) v[x].r2max=1;
return;
}
lc[x]=++size;build(lc[x],L,mid);
rc[x]=++size;build(rc[x],mid+1,R);
v[x]=merge(v[lc[x]],v[rc[x]],r[lc[x]]-l[lc[x]]+1,r[rc[x]]-l[rc[x]]+1);
}
segnode merge(segnode A,segnode B,int al,int bl)
{
segnode C;
if (B.r2max==bl) C.r2max=B.r2max+A.r2max;
else C.r2max=B.r2max;
if (B.r1max==bl) C.r1max=B.r1max+A.r1max;
else C.r1max=B.r1max;
if (A.r1max==al&&B.r1max==bl) C.va=1;
else if (A.r2max==al&&B.r2max==bl) C.va=2;
else C.va=-1;
return C;
}
void ch(int x,int y)
{
if (v[x].va==2&&y==-1)
{
v[x].r1max=v[x].r2max;v[x].r2max=0;
v[x].va=1;
}else if (v[x].va==1&&y==1)
{
v[x].r2max=v[x].r1max;v[x].r1max=0;
v[x].va=2;
}else if (v[x].va==3&&y==-1)
{
v[x].r2max=1;
v[x].va=2;
}else if (v[x].va==0&&y==1)
{
v[x].r1max=1;
v[x].va=1;
}else
{
v[x].va+=y;v[x].r1max=v[x].r2max=0;
}
}
void pushdown(int x)
{
if (l[x]==r[x]||!lazy[x]) return;
lazy[lc[x]]+=lazy[x];lazy[rc[x]]+=lazy[x];ch(lc[x],lazy[x]);ch(rc[x],lazy[x]);lazy[x]=0;
}
void modify(int x,int L,int R,int d)
{
if (L>R) return;
pushdown(x);
if (l[x]==L&&r[x]==R)
{
lazy[x]=d;ch(x,d);return;
}else
{
int mid=(l[x]+r[x])>>1;
if (L>mid) modify(rc[x],L,R,d);
else if (R<=mid) modify(lc[x],L,R,d);
else {modify(lc[x],L,mid,d);modify(rc[x],mid+1,R,d);}
}
v[x]=merge(v[lc[x]],v[rc[x]],r[lc[x]]-l[lc[x]]+1,r[rc[x]]-l[rc[x]]+1);
}
segnode get(int x,int L,int R)
{
pushdown(x);
if (l[x]==L&&r[x]==R) return v[x];
int mid=(l[x]+r[x])>>1;
if (R<=mid) return get(lc[x],L,R);
else if (L>mid) return get(rc[x],L,R);
else return merge(get(lc[x],L,mid),get(rc[x],mid+1,R),mid-L+1,R-mid);
}
}tree;
void change(int u,int d)
{
if (d==1)
{
int rt=root[top[u]];
int nl=len[top[u]];
segnode tmp=tree.get(rt,1,nl);
int le=nl-tmp.r1max+1;
tree.modify(rt,le,nl,1);
if (le>1) tree.modify(rt,le-1,le-1,1);
while (rt!=1&&tmp.r1max==nl)
{
u=fa[top[u]];
nl=Pos[u];
rt=root[top[u]];
tmp=tree.get(rt,1,nl);
le=nl-tmp.r1max+1;
tree.modify(rt,le,nl,1);
if (le>1) tree.modify(rt,le-1,le-1,1);
}
}else
{
int rt=root[top[u]];
int nl=len[top[u]];
segnode tmp=tree.get(rt,1,nl);
int le=nl-tmp.r2max+1;
tree.modify(rt,le,nl,-1);
if (le>1) tree.modify(rt,le-1,le-1,-1);
while (rt!=1&&tmp.r2max==nl)
{
u=fa[top[u]];
nl=Pos[u];
rt=root[top[u]];
tmp=tree.get(rt,1,nl);
le=nl-tmp.r2max+1;
tree.modify(rt,le,nl,-1);
if (le>1) tree.modify(rt,le-1,le-1,-1);
}
}
}
int main()
{
scanf("%d",&n);int i,j,y;
FOR(i,1,n)
{
FOR(j,0,2) {scanf("%d",&br[i][j]);fa[br[i][j]]=i;}
}
FOR(i,1,2*n+1) {scanf("%d",&sum[i+n]);sum[i+n]++;}
csiz(1);
divide(1,0);
FOR(i,1,3*n+1)
if (top[i]==i)
{
root[i]=++tree.size;
FOR(j,0,li[i].size()-1) now[j+1]=sum[li[i][j]];
tree.build(tree.size,1,len[top[i]]);
}
scanf("%d",&q);
FOR(i,1,q)
{
scanf("%d",&y);
change(y,sum[y]==1?1:-1);
if (sum[y]==1) sum[y]++;else sum[y]--;
segnode tmp=tree.get(1,1,1);
printf("%d\n",tmp.va>1);
}
return 0;
}