/* Author: rrrr_wys
 **/

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
typedef double db;
typedef long long ll;
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;

const int N = 2000110;
const int P = 998244353;

int n, q, fa[N], d[N], ans[N], num[N];
vector<int> G[N], Q[N];
void dfs(int u, int dep) {
  map<int, int> M;
  for (int qi : Q[u]) {
    M[d[qi]] = num[d[qi]];
  }
  for (int v : G[u]) {
    dfs(v, dep + 1);
  }
  num[dep]++;
  for (int qi : Q[u]) {
    ans[qi] = num[d[qi]] - M[d[qi]];
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  rep(i, 2, n) cin >> fa[i], G[fa[i]].pb(i);

  cin >> q;
  rep(i, 1, q) {
    int u;
    cin >> u >> d[i];
    Q[u].pb(i);
  }

  dfs(1, 0);
  rep(i, 1, q) cout << ans[i] << "\n";
}
//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<cstring>
#include<algorithm>


using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

const int bm = 200010;
int BIT[bm];
void add(int A) {
	while (A <= bm) {
		BIT[A]++;
		A += A & -A;
	}
}
int query(int A) {
	int ret = 0;
	while (A > 0) {
		ret += BIT[A];
		A -= A & -A;
	}
	return ret;
}

int Q[200001], ne[200001], he[200001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int H = getint(), W = getint(), M = getint();

	int X[200001], Y[200001];
	rep1(i, H) X[i] = W;
	rep1(i, W) Y[i] = H;
	rep(i, M) {
		int x = getint(), y = getint();
		if (y - 1 < X[x]) X[x] = y - 1;
		if (x - 1 < Y[y]) Y[y] = x - 1;
	}
	ll kotae = 1;
	int k = 1;
	for (int i = 2; i <= Y[1]; i++) {
		kotae += X[i];
		Q[k] = i;
		ne[k] = he[X[i]];
		he[X[i]] = k++;
	}

	int atta = X[1];
	for (int i = W; i > atta; i--) {
		for (int q = he[i]; q; q = ne[q]) {
			add(Q[q]);
		}
	}
	for (int i = atta; i >= 2; i--) {
		for (int q = he[i]; q; q = ne[q]) {
			add(Q[q]);
		}
		int are = query(Y[i]);
		kotae += Y[i] - are;
	}

	printf("%lld\n", kotae);

	Would you please return 0;
}