#include <bits/stdc++.h>
using namespace std;
int const N = 100000 + 10;
int ans[N], sum, a[N], c[N];
int n, m, block, root, id[N], size[N];
int ne[N << 1], to[N << 1], first[N], tot;
int num[N], tim[N];
void add(int u, int v) {
  ne[tot] = first[u];
  to[tot] = v;
  first[u] = tot++;
}
struct Node {
  int l, r, id, k;
  bool operator<(const Node& e) const {
    return l / block < e.l / block || l / block == e.l / block && r < e.r;
  }
} q[N];
int dfs(int u, int f) {
  id[u] = ++tot;
  size[u] = 1;
  for (int i = first[u]; ~i; i = ne[i]) {
    int v = to[i];
    if (v == f) continue;
    size[u] += dfs(v, u);
  }
  return size[u];
}
void Init() {
  root = 1;
  memset(first, -1, sizeof(first));
  scanf("%d%d", &n, &m);
  block = (int)ceil(pow(n, 0.5));
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
  }
  tot = 0;
  dfs(root, -1);
  for (int i = 1; i <= n; i++) a[id[i]] = c[i];
  for (int i = 1; i <= m; i++) {
    int v;
    scanf("%d%d", &v, &q[i].k);
    q[i].l = id[v];
    q[i].r = id[v] + size[v] - 1;
    q[i].id = i;
  }
  sort(q + 1, q + 1 + m);
}
void add(int pos) {
  num[a[pos]]++;
  tim[num[a[pos]]]++;
}
void del(int pos) {
  tim[num[a[pos]]]--;
  num[a[pos]]--;
}
int main() {
  Init();
  int L = 1, R = 0;
  for (int i = 1; i <= m; i++) {
    while (L < q[i].l) del(L++);
    while (L > q[i].l) add(--L);
    while (R < q[i].r) add(++R);
    while (R > q[i].r) del(R--);
    ans[q[i].id] = tim[q[i].k];
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
