#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
signed main() {
cin.tie(0); ios::sync_with_stdio(false);
const ll SQRT = 300;
ll N, R, Q;
cin >> N >> R >> Q;
vector<ll> reg(N);
vector<vector<ll>> adj(N);
for(ll i = 0; i < N; i++) {
if (i) {
ll p; cin >> p; p--;
adj[p].push_back(i);
cin >> reg[i];
} else cin >> reg[i];
reg[i]--;
}
vector<ll> in(N), out(N);
ll cnt = 0;
function<void(ll)> tour = [&](ll v) {
in[v] = cnt++;
for(ll &u: adj[v]) tour(u);
out[v] = cnt++;
};
tour(0);
vector<vector<ll>> pos(R); // for every region r, the sorted positions of each person relative to euler tour timing
for(ll i = 0; i < N; i++) {
pos[reg[i]].push_back(in[i]);
}
vector<vector<ll>> sigma(R);
function<void(ll, ll, ll)> dfs = [&](ll v, ll r, ll anc_cnt) {
sigma[r][reg[v]] += anc_cnt;
if (reg[v] == r) anc_cnt++;
for(ll &u: adj[v]) dfs(u, r, anc_cnt);
};
for(ll r = 0; r < R; r++) {
sort(pos[r].begin(), pos[r].end());
if (pos[r].size() > SQRT) {
sigma[r].resize(R);
dfs(0, r, 0);
}
}
for(ll q = 0; q < Q; q++) {
ll a, b; cin >> a >> b; a--, b--;
if (pos[a].size() > SQRT) cout << pos[a][b] << endl;
else {
ll re = 0;
for(ll &v: pos[a]) {
auto lb = lower_bound(pos[b].begin(), pos[b].end(), in[v]);
auto rb = lower_bound(pos[b].begin(), pos[b].end(), out[v]);
if (lb == pos[b].end()) continue;
if (rb == pos[b].begin()) continue;
else rb--;
re += rb-lb+1;
}
cout << re << endl;
}
}
}