#include <bits/stdc++.h>
using namespace std;
const long long bs = 300;
long long le = 0, ri = -1;
struct Query {
  long long l, r, k, qno;
  bool operator<(const Query &other) const {
    if (l / bs != other.l / bs) return l < other.l;
    return ((l / bs) & 1) ? (r < other.r) : (r > other.r);
  }
};
const long long nax = 100005;
long long timer = 0, tin[nax], tout[nax], col[nax], flat[nax], cnt[nax] = {0},
          suff[nax] = {0}, ans[nax];
vector<long long> g[nax];
void dfs(long long u, long long p) {
  tin[u] = ++timer;
  flat[timer] = col[u];
  for (auto &k : g[u])
    if (k != p) dfs(k, u);
  tout[u] = timer;
}
void add(long long pos) {
  cnt[flat[pos]]++;
  suff[cnt[flat[pos]]]++;
}
void del(long long pos) {
  suff[cnt[flat[pos]]]--;
  cnt[flat[pos]]--;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> col[i];
  for (long long i = 0; i < n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 1);
  vector<Query> qry;
  for (long long i = 0; i < m; i++) {
    long long u, k;
    cin >> u >> k;
    qry.push_back({tin[u], tout[u], k, i + 1});
  }
  sort(qry.begin(), qry.end());
  for (auto &q : qry) {
    while (le > q.l) le--, add(le);
    while (ri < q.r) ri++, add(ri);
    while (le < q.l) del(le), le++;
    while (ri > q.r) del(ri), ri--;
    ans[q.qno] = suff[q.k];
  }
  for (long long i = 1; i <= m; i++) cout << ans[i] << '\n';
}
