#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 10;
int dfn[MAXN], n, m, tot, head[MAXN << 1];
int cnt[MAXN], ans[MAXN], dfstime, rk[MAXN];
int bl[MAXN], S, sum[MAXN], c[MAXN], siz[MAXN];
pair<int, int> Rem[MAXN];
struct edge {
  int nxt, to;
} e[MAXN << 1];
inline void add(int x, int y) {
  e[++tot].to = y;
  e[tot].nxt = head[x];
  head[x] = tot;
}
void dfs(int x, int pre) {
  rk[dfn[x] = ++dfstime] = x;
  Rem[x].first = dfstime;
  siz[x] = 1;
  for (int i = head[x]; i; i = e[i].nxt) {
    int j = e[i].to;
    if (pre == j) continue;
    dfs(j, x);
    siz[x] += siz[j];
  }
  Rem[x].second = dfstime;
}
struct Q {
  int l, r, k, id;
  bool operator<(const Q& B) const {
    if (bl[l] == bl[B.l]) return r < B.r;
    return bl[l] < bl[B.l];
  }
} q[MAXN];
inline void inr(int x) { ++cnt[c[rk[x]]], ++sum[cnt[c[rk[x]]]]; }
inline void del(int x) { --sum[cnt[c[rk[x]]]], --cnt[c[rk[x]]]; }
int main() {
  scanf("%d%d", &n, &m);
  S = sqrt(n);
  for (int i = 1; i <= n; ++i) scanf("%d", &c[i]), bl[i] = (i - 1) / S + 1;
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  dfs(1, 0);
  for (int i = 1, v; i <= m; ++i) {
    scanf("%d%d", &v, &q[i].k);
    q[i].id = i;
    q[i].l = dfn[v];
    q[i].r = dfn[v] + siz[v] - 1;
  }
  sort(q + 1, q + m + 1);
  int l = 1, r = 0;
  for (int i = 1; i <= m; ++i) {
    int ql = q[i].l, qr = q[i].r;
    while (l < ql) del(l++);
    while (l > ql) inr(--l);
    while (r < qr) inr(++r);
    while (r > qr) del(r--);
    ans[q[i].id] = sum[q[i].k];
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
  return 0;
}
