#include<bits/stdc++.h>
#define gc getchar
#define pc putchar
#define N 200005
#define ll long long
using namespace std;
template<class T>void read(T&x) {
	T f=1;x=0;char c=gc();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=gc();}
	while('0'<=c&&c<='9'){x=x*10+c-'0';c=gc();}
	x*=f;
}
template<class T>void print(T x,char c) {
	if(x<0)pc('-'),x=-x;int s[20],top=0;
	while(s[++top]=x%10,x/=10);
	while(top)pc(s[top--]+'0');pc(c);
}
int n,m,Q,a[N],b[N],tot,lis[N];
int T[N],X[N],Y[N];
ll sum[N<<2];
int root1,root2,all,lc[N<<2],rc[N<<2],siz[N<<2];
void Insert(int &rt,int l,int r,int pos,int d) {
	if(!rt)rt = ++all;
	sum[rt] += d*lis[pos];siz[rt] += d;
	if(l == r)return;
	int mid = l+r>>1;
	if(pos <= mid)Insert(lc[rt],l,mid,pos,d);
	else Insert(rc[rt],mid+1,r,pos,d);
}
ll moresum(int rt,int l,int r,int pos) {
	if(!rt)return 0;
	if(pos <= l)return sum[rt];
	if(r < pos)return 0;
	int mid = l+r>>1;
	return moresum(lc[rt],l,mid,pos)+moresum(rc[rt],mid+1,r,pos);
}
int lesssiz(int rt,int l,int r,int pos) {
	if(!rt)return 0;
	if(r <= pos)return siz[rt];
	if(pos < l)return 0;
	int mid = l+r>>1;
	return lesssiz(lc[rt],l,mid,pos)+lesssiz(rc[rt],mid+1,r,pos);
}
int main() {
	read(n),read(m),read(Q);lis[tot = 1] = 0;
	for(int i=1; i<=Q; ++i)read(T[i]),read(X[i]),read(Y[i]),lis[++tot] = Y[i];
	sort(lis+1,lis+tot+1);tot = unique(lis+1,lis+tot+1)-lis-1;
	for(int i=1; i<=n; ++i)Insert(root1,1,tot,1,1);
	for(int i=1; i<=m; ++i)Insert(root2,1,tot,1,1);
	ll ans = 0;
	for(int i=1; i<=Q; ++i) {
		int x = X[i],y = lower_bound(lis+1,lis+tot+1,Y[i])-lis;
		if(T[i] == 1) {
			ans -= moresum(root2,1,tot,a[x]);
			ans -= 1ll*lis[a[x]]*lesssiz(root2,1,tot,a[x]-1);
			Insert(root1,1,tot,a[x],-1);Insert(root1,1,tot,a[x] = y,1);
			ans += moresum(root2,1,tot,a[x]);
			ans += 1ll*lis[a[x]]*lesssiz(root2,1,tot,a[x]-1);
		}
		else {
			ans -= moresum(root1,1,tot,b[x]);
			ans -= 1ll*lis[b[x]]*lesssiz(root1,1,tot,b[x]-1);
			Insert(root2,1,tot,b[x],-1);Insert(root2,1,tot,b[x] = y,1);
			ans += moresum(root1,1,tot,b[x]);
			ans += 1ll*lis[b[x]]*lesssiz(root1,1,tot,b[x]-1);
		}
		print(ans,'\n');
	}
}
#include<bits/stdc++.h>
#define int long long
using namespace std;

int n,q;
int p[200010],in[200010],out[200010],dep[200010],cnt;
int ver[200010],nxt[200010],head[200010],tot;

vector<int> g[200010];

bool cmp(int x,int y)
{
	return in[x]<in[y];
}

template<typename Tp>
void read(Tp &x)
{
	x=0;int f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}x*=f;
}

void add(int u,int v)
{
	ver[++tot]=v;
	nxt[tot]=head[u];
	head[u]=tot;
}

void dfs(int x,int deep)
{
	in[x]=++cnt;
	dep[x]=deep;
	g[deep].push_back(x);
	for(int i=head[x];i;i=nxt[i])
	{
		int y=ver[i];
		dfs(y,deep+1);
	}
	out[x]=cnt;
}

signed main()
{
	read(n);
	for(int i=2;i<=n;i++) 
	{
		read(p[i]);
		add(p[i],i);
	}
	dfs(1,1);
	for(int i=1;i<=n;i++) g[i].push_back(0);
	for(int i=1;i<=n;i++) sort(g[i].begin(),g[i].end(),cmp);
	read(q);
	for(int i=1;i<=q;i++)
	{
		int u,d;
		read(u),read(d);
		if(dep[u]>d+1) printf("0\n");
		else
		{
			d++;
			int l=1,r=g[d].size()-1,ans1=0,ans2=0;
			while(l<=r)
			{
				int mid=(l+r)>>1;
				if(in[g[d][mid]]<in[u]) ans1=mid,l=mid+1;
				else r=mid-1;
			}
			ans1++;
			l=1,r=g[d].size()-1;
			while(l<=r)
			{
				int mid=(l+r)>>1;
				if(in[g[d][mid]]<=out[u]) ans2=mid,l=mid+1;
				else r=mid-1;
			}
			printf("%d\n",ans2-ans1+1);
		}
	}
	return 0;
}
