#include <bits/stdc++.h>
using namespace std;
struct query {
  int l;
  int r;
  int idx;
  int k;
};
query Q[100001];
vector<int> arr[100001];
int F[200002], S[100001], T[100001], timer = 0;
int nodef[100001], ans[100001], col[100001], elef[100001], ff[100001];
int bucket[100001];
bool comp(query a, query b) {
  int x = a.l / 700;
  ;
  int y = b.l / 700;
  ;
  if (x != y) {
    return x < y;
  }
  return a.r < b.r;
}
int getBlock(int idx) {
  int xx = (idx / 700) + 1;
  return xx;
}
void dfs(int node, int parent) {
  S[node] = timer;
  F[timer] = node;
  timer++;
  for (int child : arr[node]) {
    if (child != parent) {
      dfs(child, node);
    }
  }
  T[node] = timer;
  F[timer] = node;
  timer++;
}
void add(int pos) {
  int node = F[pos];
  int c = col[node];
  nodef[node]++;
  if (nodef[node] == 2) {
    elef[c]++;
    ff[elef[c]]++;
    bucket[getBlock(elef[c])]++;
    ff[elef[c] - 1]--;
    bucket[getBlock(elef[c] - 1)]--;
  }
}
void remove(int pos) {
  int node = F[pos];
  int c = col[node];
  nodef[node]--;
  if (nodef[node] == 1) {
    elef[c]--;
    ff[elef[c]]++;
    bucket[getBlock(elef[c])]++;
    ff[elef[c] + 1]--;
    bucket[getBlock(elef[c] + 1)]--;
  }
}
int getAns(int k, int n) {
  int ans = 0;
  int LB = getBlock(k);
  int RB = getBlock(n);
  if (LB == RB) {
    for (int i = k; i <= n; i++) {
      ans += ff[i];
    }
  } else {
    int kk = LB * 700;
    for (int i = k; i <= kk; i++) {
      ans += ff[i];
    }
    for (int i = (LB + 1); i < RB; i++) {
      ans += bucket[i];
    }
    kk = RB * 700;
    ;
    for (int i = kk + 1; i <= n; i++) {
      ans += ff[i];
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> col[i];
  }
  for (int i = 1; i <= n - 1; i++) {
    int a, b;
    cin >> a >> b;
    arr[a].push_back(b);
    arr[b].push_back(a);
  }
  timer = 1;
  dfs(1, -1);
  for (int i = 1; i <= q; i++) {
    int a, b;
    cin >> a >> b;
    Q[i].idx = i;
    Q[i].l = S[a];
    Q[i].r = T[a];
    Q[i].k = b;
  }
  sort(Q + 1, Q + 1 + q, comp);
  int ML = 1, MR = 0;
  for (int i = 1; i <= q; i++) {
    int L = Q[i].l;
    int R = Q[i].r;
    int k = Q[i].k;
    int idx = Q[i].idx;
    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[idx] = getAns(k, n);
  }
  for (int i = 1; i <= q; i++) {
    cout << ans[i] << '\n';
    ;
  }
  return 0;
}
