#include <bits/stdc++.h>
using namespace std;
unordered_map<int, int> cnt[100005], res[100005];
vector<int> adj[100005];
vector<pair<int, int> > que[100005];
void merg(int u, int v) {
  if (cnt[u].size() < cnt[v].size()) swap(cnt[u], cnt[v]), swap(res[u], res[v]);
  for (auto nx : cnt[v]) {
    int x = cnt[u][nx.first];
    cnt[u][nx.first] += nx.second;
    for (int j = 0; j < nx.second; j++) res[u][x + j + 1]++;
  }
  return;
}
int n, q, col[100005], ans[100005];
void dfs(int nw, int bf) {
  cnt[nw][col[nw]]++;
  res[nw][1]++;
  for (int nx : adj[nw])
    if (nx != bf) {
      dfs(nx, nw);
      merg(nw, nx);
    }
  for (pair<int, int> i : que[nw]) ans[i.second] = res[nw][i.first];
  return;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", &col[i]);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 0, x, y; i < q; i++) {
    scanf("%d%d", &x, &y);
    que[x].push_back({y, i});
  }
  dfs(1, -1);
  for (int i = 0; i < q; i++) printf("%d\n", ans[i]);
  return 0;
}
