#include <bits/stdc++.h>
using namespace std;
inline int64_t gilbertOrder(long long x, long long y, long long pow,
                            long long rotate) {
  if (pow == 0) {
    return 0;
  }
  long long hpow = 1 << (pow - 1);
  long long seg = (x < hpow) ? ((y < hpow) ? 0 : 3) : ((y < hpow) ? 1 : 2);
  seg = (seg + rotate) & 3;
  const long long rotateDelta[4] = {3, 0, 0, 1};
  long long nx = x & (x ^ hpow), ny = y & (y ^ hpow);
  long long nrot = (rotate + rotateDelta[seg]) & 3;
  int64_t subSquareSize = int64_t(1) << (2 * pow - 2);
  int64_t ans = seg * subSquareSize;
  int64_t add = gilbertOrder(nx, ny, pow - 1, nrot);
  ans += (seg == 1 || seg == 2) ? add : (subSquareSize - add - 1);
  return ans;
}
long long le = 0, ri = -1;
struct Query {
  long long l, r, k, qno, ord;
  void calc() { ord = gilbertOrder(l, r, 21, 0); }
  bool operator<(const Query &other) const { return ord < other.ord; }
};
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, -1});
    qry[((long long)qry.size()) - 1].calc();
  }
  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';
}
