#include <bits/stdc++.h>
using namespace std;
const int sz = 1000;
const int N = 1e5 + 5;
int a[N], subtree[N], cnt[N], freq[N], k(1), col[N], ans[N];
vector<int> v[N];
void dfs(int node, int par) {
  subtree[node] = 1;
  a[k++] = node;
  cnt[node] = k - 1;
  for (auto i : v[node])
    if (i != par) {
      dfs(i, node);
      subtree[node] += subtree[i];
    }
}
struct node {
  int l, r, k, idx;
} q[N];
inline void emi(int cl) {
  freq[cnt[col[a[cl]]]] -= 1;
  cnt[col[a[cl]]] -= 1;
}
inline void nem(int cl) {
  cnt[col[a[cl]]] += 1;
  freq[cnt[col[a[cl]]]] += 1;
}
signed main() {
  int n, m, nod, l, cl(0), cr(0);
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", col + i);
  for (int i = 1; i < n; ++i) {
    scanf("%d %d", &l, &nod);
    v[l].push_back(nod);
    v[nod].push_back(l);
  }
  dfs(1, -1);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &nod, &q[i].k);
    q[i].idx = i;
    q[i].l = cnt[nod];
    q[i].r = cnt[nod] + subtree[nod] - 1;
  }
  sort(q, q + m, [](node x, node y) {
    int a = x.l / sz, b = y.l / sz;
    if (a != b) return a < b;
    return x.r < y.r;
  });
  memset(cnt, 0, sizeof cnt);
  for (int i = 0; i < m; ++i) {
    int l = q[i].l, r = q[i].r;
    while (cl < l) emi(cl++);
    while (cl > l) nem(--cl);
    while (cr <= r) nem(cr++);
    while (cr > r + 1) emi(--cr);
    ans[q[i].idx] = freq[q[i].k];
  }
  for (int i = 0; i < m; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
