#include <bits/stdc++.h>
using namespace std;
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
struct info {
  map<int, int> colCnt;
  vector<long long> cnt;
  int nm = 0;
  void add(int x) {
    int cur = colCnt[x]++;
    if (cnt.size() == cur)
      cnt.push_back(1);
    else
      cnt[cur]++;
    nm++;
  }
  info *merge(info *oth) {
    if (nm < oth->nm)
      return oth->merge(this);
    else {
      for (auto e : oth->colCnt)
        for (int i = 0; i < e.second; i++) add(e.first);
      return this;
    }
  }
  int get(int k) {
    if (k > cnt.size()) return 0;
    return cnt[k - 1];
  }
};
const int maxn = 1e5 + 10;
int c[maxn], ans[maxn];
vector<long long> graph[maxn];
vector<pair<long long, long long> > qu[maxn];
info *dfs(int u, int p) {
  info *curInfo = new info();
  curInfo->add(c[u]);
  for (auto &e : graph[u])
    if (e != p) {
      auto res = dfs(e, u);
      curInfo = curInfo->merge(res);
    }
  for (auto &e : qu[u]) ans[e.first] = curInfo->get(e.second);
  return curInfo;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &c[i]);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    qu[a].push_back(pair<long long, long long>(i, b));
  }
  dfs(0, 0);
  for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
}
