#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7;
vector<int> vt[MAXN];
struct node {
  int l, r, k;
  int id;
  int pos;
} q[MAXN];
bool cmp(node c, node d) {
  if (c.pos == d.pos) return c.r < d.r;
  return c.l < d.l;
}
int n, m, k;
int a[MAXN], c[MAXN], block[MAXN];
int in[MAXN], out[MAXN], tot;
long long int cnt[MAXN], sum[MAXN];
long long int ans[MAXN];
void add(int x) {
  cnt[c[x]]++;
  sum[cnt[c[x]]]++;
}
void del(int x) {
  sum[cnt[c[x]]]--;
  cnt[c[x]]--;
}
void dfs(int u, int fa) {
  in[u] = ++tot;
  c[tot] = a[u];
  for (int i = 0; i < vt[u].size(); i++) {
    int v = vt[u][i];
    if (v == fa) continue;
    dfs(v, u);
  }
  out[u] = tot;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    memset(c, 0, sizeof(c));
    memset(sum, 0, sizeof(sum));
    memset(cnt, 0, sizeof(cnt));
    memset(in, 0, sizeof(in));
    memset(out, 0, sizeof(out));
    tot = 0;
    int s = sqrt(n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]), block[i] = (i - 1) / s + 1;
    for (int i = 1; i < n; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      vt[x].push_back(y);
      vt[y].push_back(x);
    }
    dfs(1, 1);
    for (int i = 1; i <= m; i++) {
      scanf("%d%d", &q[i].l, &q[i].k);
      q[i].r = out[q[i].l];
      q[i].l = in[q[i].l];
      q[i].id = i;
      q[i].pos = block[q[i].l];
    }
    sort(q + 1, q + m + 1, cmp);
    int l = 1, r = 0;
    for (int i = 1; i <= m; i++) {
      while (l < q[i].l) {
        del(l);
        l++;
      }
      while (l > q[i].l) {
        l--;
        add(l);
      }
      while (r < q[i].r) {
        r++;
        add(r);
      }
      while (r > q[i].r) {
        del(r);
        r--;
      }
      ans[q[i].id] = sum[q[i].k];
    }
    for (int i = 1; i <= m; i++) printf("%lld\n", ans[i]);
  }
}
