#include using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair; using tll=tuple; using ld=long double; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++) #define all(v) v.begin(),v.end() #define len(v) ((ll)v.size()) template inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template inline bool chmax(T &a,T b){ if(a struct fenwick_tree{ vector v; int n; fenwick_tree(int x){ n=x+1; v.assign(n+1,0); } fenwick_tree(vector &a){ n=(int)a.size()+1; v.assign(n+1,0); if((int)a.size()==0) return; v[1]=a[0]; for(int i=0;i>=1){ if(x+k<=n&&v[x+k]> g; vector ord,in,out; void dfs(ll x,ll p){ in[x]=len(ord); ord.push_back(x); for(auto i:g[x]){ if(i==p) continue; dfs(i,x); } out[x]=len(ord); ord.push_back(x); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll n; cin >> n; g.resize(n); in.resize(n); out.resize(n); vector p(n,-1); replr(i,1,n){ cin >> p[i]; p[i]--; g[i].push_back(p[i]); g[p[i]].push_back(i); } string s(n,'x'); replr(i,1,n) cin >> s[i]; ll q; cin >> q; vector u(q),v(q); rep(i,q){ cin >> u[i] >> v[i]; u[i]--; v[i]--; } dfs(0,-1); ll sz=len(ord); vector> lr(sz); rep(i,q){ if(out[u[i]]>out[v[i]]) swap(u[i],v[i]); u[i]=out[u[i]]; v[i]=out[v[i]]; lr[u[i]].insert(v[i]); } fenwick_tree BIT(sz); replr(i,1,n){ if(s[i]=='#') BIT.add(in[i],in[i]+1,1); } rep(i,sz){ ll x=in[ord[i]],y=out[ord[i]]; if(i==x) x=y; if(!((BIT.get(i)+BIT.get(x))&1)) continue; if(lr[i].empty()) continue; ll j=*begin(lr[i]); BIT.add(i,j,1); lr[i].erase(j); if(len(lr[i])