#include <bits/stdc++.h>
using namespace std;
map<int, int> a[1 << 20], b[1 << 20];
const int lim = 1e5;
vector<int> s[1 << 20];
vector<pair<int, int> > v[1 << 20];
int dp[1 << 20];
void upd(int c, int i, int val) {
  for (; i <= lim; i += i & (-i)) {
    a[c][i] += val;
    if (!a[c][i]) a[c].erase(i);
  }
}
int query(int c, int i) {
  int ans = 0;
  for (; i; i -= i & (-i))
    if (a[c].count(i)) ans += a[c][i];
  return ans;
}
void Merge(int first, int second) {
  if (b[first].size() < b[second].size())
    swap(b[first], b[second]), swap(a[first], a[second]);
  for (auto it : b[second])
    if (!b[first].count(it.first))
      b[first][it.first] = it.second, upd(first, it.second, 1);
    else {
      int was = b[first][it.first];
      upd(first, was, -1);
      was += it.second;
      upd(first, was, 1);
      b[first][it.first] = was;
    }
  a[second].clear();
  b[second].clear();
}
void dfs(int node, int prev) {
  for (auto it : s[node])
    if (it != prev) dfs(it, node), Merge(node, it);
  for (auto it : v[node])
    dp[it.second] = query(node, lim) - query(node, it.first - 1);
}
int main(void) {
  int n, m;
  ios_base ::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    int val;
    cin >> val;
    b[i][val]++;
    upd(i, 1, 1);
  }
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    s[a].push_back(b);
    s[b].push_back(a);
  }
  for (int i = 1; i <= m; ++i) {
    int a, b;
    cin >> a >> b;
    v[a].push_back({b, i});
  }
  dfs(1, 0);
  for (int i = 1; i <= m; ++i) cout << dp[i] << '\n';
  return 0;
}
