#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int dx[8] = {1, -1, 0, 0, -1, -1, 1, 1};
int dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
const long long inf = 1000000007;
vector<int> adj[200010], vis(200010, 0), dis(200010, 0), fin(200010, 0),
    col(200010, 0), res(200010, 0);
int myrandom(int i) { return std::rand() % i; }
int t = 1;
int bit[200010];
void dfs(int a) {
  vis[a] = 1;
  dis[a] = t;
  res[t] = col[a];
  t++;
  for (auto i : adj[a]) {
    if (vis[i] == 0) {
      dfs(i);
    }
  }
  fin[a] = t;
}
inline long long hilbertOrder(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;
  long long subSquareSize = 1ll << (2 * pow - 2);
  long long ans = seg * subSquareSize;
  long long add = hilbertOrder(nx, ny, pow - 1, nrot);
  ans += (seg == 1 || seg == 2) ? add : (subSquareSize - add - 1);
  return ans;
}
struct Query {
  long long l, r, idx, val;
  long long ord;
  inline void calcOrder() { ord = hilbertOrder(l, r, 21, 0); }
};
inline bool operator<(const Query &a, const Query &b) { return a.ord < b.ord; }
void update(int id, int delta) {
  while (id <= 100000) {
    bit[id] += delta;
    id += id & -id;
  }
}
int get_sum(int id) {
  int res = 0;
  while (id) {
    res += bit[id];
    id -= id & -id;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  memset(bit, 0, sizeof(bit));
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> col[i];
  }
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1);
  vector<Query> v(m);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[i].l = dis[a];
    v[i].r = fin[a] - 1;
    v[i].idx = i;
    v[i].val = b;
    v[i].calcOrder();
  }
  sort((v).begin(), (v).end());
  vector<int> ans(m + 1, 0);
  vector<int> cnt(100010, 0);
  int l = 1, r = n;
  for (int i = 1; i <= n; i++) {
    cnt[res[i]]++;
  }
  for (int i = 1; i <= 100000; i++) {
    if (cnt[i] > 0) {
      update(cnt[i], 1);
    }
  }
  for (int i = 0; i < m; i++) {
    while (l > v[i].l) {
      if (cnt[res[l - 1]]) update(cnt[res[l - 1]], -1);
      update(cnt[res[l - 1]] + 1, 1);
      cnt[res[l - 1]]++;
      l--;
    }
    while (r < v[i].r) {
      if (cnt[res[r + 1]]) update(cnt[res[r + 1]], -1);
      update(cnt[res[r + 1]] + 1, 1);
      cnt[res[r + 1]]++;
      r++;
    }
    while (l < v[i].l) {
      update(cnt[res[l]], -1);
      cnt[res[l]]--;
      if (cnt[res[l]]) update(cnt[res[l]], 1);
      l++;
    }
    while (r > v[i].r) {
      update(cnt[res[r]], -1);
      cnt[res[r]]--;
      if (cnt[res[r]]) update(cnt[res[r]], 1);
      r--;
    }
    int sum = get_sum(100000) - get_sum(v[i].val - 1);
    ans[v[i].idx] = sum;
  }
  for (int i = 0; i < m; i++) {
    cout << ans[i] << '\n';
  }
}
