#include <bits/stdc++.h>
using namespace std;
const long long int maxN = 100001;
long long int BLK = 500;
vector<long long int> v[maxN];
long long int a[maxN], start[maxN], e[maxN], timer, ft[2 * maxN];
long long int nodeF[maxN], eleF[maxN], FF[maxN] = {0}, ans[maxN];
long long int bucket[maxN], n, q, sz;
struct query {
  long long int l, r, ind, k;
};
query Q[maxN];
long long int getBLK(long long int n) { return (n + BLK - 1) / BLK; }
void dfs(long long int n, long long int p) {
  ft[timer] = n;
  start[n] = timer;
  timer++;
  for (auto i : v[n]) {
    if (i != p) {
      dfs(i, n);
    }
  }
  e[n] = timer;
  ft[timer] = n;
  timer++;
}
void add(long long int inx) {
  long long int node = ft[inx];
  long long int col = a[node];
  nodeF[node]++;
  if (nodeF[node] == 2) {
    eleF[col]++;
    FF[eleF[col]]++;
    bucket[getBLK(eleF[col])]++;
    FF[eleF[col] - 1]--;
    bucket[getBLK(eleF[col] - 1)]--;
  }
}
void remove(long long int inx) {
  long long int node = ft[inx];
  long long int col = a[node];
  nodeF[node]--;
  if (nodeF[node] == 1) {
    eleF[col]--;
    FF[eleF[col]]++;
    bucket[getBLK(eleF[col])]++;
    FF[eleF[col] + 1]--;
    bucket[getBLK(eleF[col] + 1)]--;
  }
}
bool comp(query a, query b) {
  if (a.l / BLK != b.l / BLK) {
    return a.l / BLK < b.l / BLK;
  }
  if (a.l / BLK % 2)
    return a.r < b.r;
  else
    return a.r > b.r;
}
long long int getans(long long int k, long long int n) {
  long long int ans = 0;
  long long int L = getBLK(k);
  long long int R = getBLK(n);
  if (L == R) {
    for (long long int i = k; i < n + 1; i++) ans += FF[i];
    return ans;
  }
  for (long long int i = k; i <= L * BLK; i++) {
    ans += FF[i];
  }
  for (long long int i = L + 1; i < R; i++) ans += bucket[i];
  for (long long int i = R * BLK + 1; i < n + 1; i++) ans += FF[i];
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> q;
  for (long long int i = 1; i < n + 1; i++) cin >> a[i];
  for (long long int i = 0; i < n - 1; i++) {
    long long int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  timer = 1;
  dfs(1, -1);
  for (long long int i = 1; i <= q; i++) {
    long long int a, k;
    cin >> a >> k;
    Q[i].l = start[a];
    Q[i].r = e[a];
    Q[i].k = k;
    Q[i].ind = i;
  }
  sort(Q + 1, Q + q + 1, comp);
  long long int ML = 0, MR = -1;
  for (long long int i = 1; i < q + 1; i++) {
    long long int L = Q[i].l;
    long long int R = Q[i].r;
    long long int ind = Q[i].ind;
    long long int k = Q[i].k;
    while (ML > L) {
      ML--;
      add(ML);
    }
    while (MR < R) {
      MR++;
      add(MR);
    }
    while (ML < L) {
      remove(ML);
      ML++;
    }
    while (MR > R) {
      remove(MR);
      MR--;
    }
    ans[ind] = getans(k, n);
  }
  for (long long int i = 1; i < q + 1; i++) cout << ans[i] << "\n";
}
long long int power(long long int x, long long int y) {
  long long int res = 1;
  x %= 1000000007;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res % 1000000007;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
