#include <bits/stdc++.h>
using namespace std;
int n, m, k, kk, i, o, pos[100000 + 10], kol[100000 + 10], c[100000 + 10],
    r[100000 + 10], t[500000 + 10], d[100000 + 10], tin[100000 + 10],
    tout[100000 + 10];
vector<int> a[100000 + 10];
struct my {
  int f;
  int s;
  int k;
  int o;
};
my b[100000 + 10];
void update(int pos, int val) {
  for (int i = pos; i <= n; i |= (i + 1)) {
    t[i] += val;
  }
}
int sum(int pos) {
  int ans = 0;
  for (int i = pos; i >= 0; i &= (i + 1), i--) {
    ans += t[i];
  }
  return ans;
}
int get(int l, int r) { return sum(r) - sum(l - 1); }
void dfs(int x, int pr = -1) {
  k++;
  tin[x] = k;
  pos[k] = x;
  for (int i = 0; i < a[x].size(); i++)
    if (pr != a[x][i]) dfs(a[x][i], x);
  tout[x] = k;
}
void add(int pos, int tr) {
  int o = c[pos];
  update(kol[o], -1);
  kol[o]++;
  update(kol[o], 1);
}
void del(int pos, int tr) {
  int o = c[pos];
  update(kol[o], -1);
  kol[o]--;
  update(kol[o], 1);
}
bool cmp(my a, my b) {
  if (a.f / kk != b.f / kk) {
    if (a.f < b.f) return true;
    return false;
  }
  if (a.s < b.s) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  kk = sqrt(n);
  for (i = 1; i <= n; i++) cin >> c[i];
  for (i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  dfs(1);
  for (i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    b[i].f = tin[x];
    b[i].s = tout[x];
    b[i].k = i;
    b[i].o = y;
  }
  sort(b + 1, b + m + 1, cmp);
  int x = b[1].f, y = b[1].s;
  for (i = x; i <= y; i++) add(pos[i], b[1].o);
  r[b[1].k] = get(b[1].o, n);
  for (i = 2; i <= m; i++) {
    for (; x > b[i].f;) {
      add(pos[x - 1], b[i].o);
      x--;
    }
    for (; y < b[i].s;) {
      add(pos[y + 1], b[i].o);
      y++;
    }
    for (; x < b[i].f;) {
      del(pos[x], b[i].o);
      x++;
    }
    for (; y > b[i].s;) {
      del(pos[y], b[i].o);
      y--;
    }
    r[b[i].k] = get(b[i].o, n);
  }
  for (i = 1; i <= m; i++) cout << r[i] << "\n";
}
