#include <bits/stdc++.h>
using namespace std;
vector<int> g[110000], p[110000];
map<int, int> a[110000];
int n, m, x, y, s[110000], k[110000], c[110000], b[110000], ans[110000],
    son[110000];
void dfs(int x, int f) {
  s[x] = 1;
  for (auto t : g[x])
    if (t != f) {
      dfs(t, x);
      s[x] += s[t];
      if (s[t] > s[son[x]]) son[x] = t;
    }
}
int lowbit(int x) { return x & -x; }
int sum(int x) {
  int ret = 0;
  while (x) {
    ret += b[x];
    x -= lowbit(x);
  }
  return ret;
}
void add(int x, int k) {
  if (!x) return;
  while (x <= n) {
    b[x] += k;
    x += lowbit(x);
  }
}
void merge(int x, int f, int keep) {
  for (auto t : g[x])
    if (t != f && t != son[x]) merge(t, x, 0);
  if (son[x]) merge(son[x], x, 1), a[x].swap(a[son[x]]);
  add(a[x][c[x]], -1);
  a[x][c[x]]++;
  add(a[x][c[x]], 1);
  for (auto t : g[x])
    if (t != f && t != son[x])
      for (auto e : a[t])
        add(a[x][e.first], -1), a[x][e.first] += e.second,
            add(a[x][e.first], 1);
  for (auto t : p[x])
    if (k[t] <= n) ans[t] = sum(n) - sum(k[t] - 1);
  if (!keep)
    for (auto e : a[x]) add(e.second, -1);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &k[i]);
    p[x].push_back(i);
  }
  dfs(1, 0);
  merge(1, 0, 0);
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
