#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <utility>
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
#define pb push_back
#define all(x) begin(x), end(x)
#define space " "
#define TEST_CASES int a; cin >> a; for (int i = 0; i < a; i++) {solve(); cout << endl;}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
void solve() {
int n, r, q; cin >> n >> r >> q;
vector<int> vec(n);
vector<vector<int>> groups(r);
vector<vector<int>> adj(n);
cin >> vec[0]; vec[0]--; groups[vec[0]].pb(0);
for (int i = 1; i < n; i++) {
int x, y; cin >> x >> y; x--; y--;
adj[i].pb(x); adj[x].pb(i);
vec[i] = y; groups[vec[i]].pb(i);
}
int block = sqrt(r);
vector<int> euler;
vector<int> sub(n, 1);
vector<int> pos(n);
vector<vector<int>> gpos(r);
vector<int> euler2;
auto dfs = [&] (auto &&self, int node, int parent) -> void {
pos[node] = euler.size();
gpos[vec[node]].pb(euler.size());
euler.pb(node);
euler2.pb(node);
for (auto x : adj[node]) {
if (x == parent) {
continue;
}
self(self, x, node);
sub[node] += sub[x];
}
euler2.pb(node);
};
dfs(dfs, 0, -1);
map<int, vector<int>> larges;
for (int i = 0; i < r; i++) {
if (groups[i].size() >= block) {
larges[i] = vector<int>(r);
int curr = 0;
vector<bool> seen(n);
for (int j = 0; j < euler2.size(); j++) {
if (vec[euler2[j]] == i) {
if (!seen[euler2[j]]) {
curr++;
}
else {
curr--;
}
}
else {
if (!seen[euler2[j]]) {
larges[i][vec[euler2[j]]] += curr;
}
}
seen[euler2[j]] = true;
}
}
}
while (q--) {
int r1, r2; cin >> r1 >> r2; r1--; r2--;
if (groups[r1].size() >= block) {
cout << larges[r1][r2] << endl;
}
else {
int res = 0;
for (auto x : groups[r1]) {
auto it = lower_bound(all(gpos[r2]), pos[x]);
auto it2 = lower_bound(all(gpos[r2]), pos[x] + sub[x]);
res += it2 - it;
}
cout << res << endl;
}
}
}
int main() {
FAST_IO;
//freopen("cowland.in", "r", stdin);
//freopen("cowland.out", "w", stdout);
//TEST_CASES;
solve(); //cout << endl;
/*int a; cin >> a;
for (int i = 1; i <= a; i++){
cout << "Case #" << i << ": ";
solve();
cout << endl;
}*/
}