#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, m, tot, maxblock;
int val[maxn], sum[maxn], ans[maxn], head[maxn], a[maxn], dfn[maxn << 1],
    fin[maxn], out[maxn], cot;
struct edge {
  int v, nxt;
} E[maxn << 1];
struct query {
  int l, r, id, k;
} q[maxn];
inline void add_edge(int u, int v) {
  ++tot;
  E[tot].v = v;
  E[tot].nxt = head[u];
  head[u] = tot;
}
inline bool cmp(query a, query b) {
  return (a.l / maxblock) == (b.l / maxblock) ? a.r < b.r : a.l < b.l;
}
inline void add(int x) {
  ++val[dfn[x]];
  ++sum[val[dfn[x]]];
}
inline void del(int x) {
  --sum[val[dfn[x]]];
  --val[dfn[x]];
}
void dfs(int x, int fa) {
  ++cot;
  dfn[cot] = a[x];
  fin[x] = cot;
  for (int i = head[x]; i; i = E[i].nxt) {
    int y = E[i].v;
    if (y == fa) continue;
    dfs(y, x);
  }
  out[x] = cot;
}
int main() {
  scanf("%d%d", &n, &m);
  maxblock = sqrt(n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    add_edge(u, v);
    add_edge(v, u);
  }
  dfs(1, 0);
  for (int i = 1, u; i <= m; ++i) {
    scanf("%d%d", &u, &q[i].k);
    q[i].id = i;
    q[i].l = fin[u];
    q[i].r = out[u];
  }
  sort(q + 1, q + m + 1, cmp);
  for (int i = 1, l = 1, r = 0; i <= m; ++i) {
    while (l > q[i].l) {
      --l;
      add(l);
    }
    while (r < q[i].r) {
      ++r;
      add(r);
    }
    while (r > q[i].r) {
      del(r);
      --r;
    }
    while (l < q[i].l) {
      del(l);
      ++l;
    }
    ans[q[i].id] = sum[q[i].k];
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
  return 0;
}
