#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }
int Set(int N, int pos) { return (N | (1 << pos)); }
int fx[] = {-1, 0, 1, 0};
int fy[] = {0, 1, 0, -1};
inline long long BigMod(long long B, long long P, long long M) {
  long long R = 1;
  while (P > 0) {
    if (P % 2 == 1) {
      R = (R * B) % M;
    }
    P /= 2;
    B = (B * B) % M;
  }
  return R;
}
const int N = 100000;
int n, q, sq, counter;
int color[N + 5], st[N + 5], ed[N + 5], cnt[N + 5], K[N + 5], ara[N + 5];
vector<int> G[N + 5];
void dfs(int node, int pre) {
  st[node] = ++counter;
  color[counter] = ara[node];
  for (int i : G[node])
    if (i != pre) dfs(i, node);
  ed[node] = counter;
}
struct data {
  int l, r, k, id;
};
bool cmp(data A, data B) {
  if (A.l / sq != B.l / sq) return A.l < B.l;
  return A.r < B.r;
}
data Q[N + 5];
int answer[N + 5];
int mol = 1, mor = 0;
void add(int pos) { ++K[++cnt[color[pos]]]; }
void remove(int pos) { K[cnt[color[pos]]--]--; }
int MO(int id) {
  int l = Q[id].l;
  int r = Q[id].r;
  int k = Q[id].k;
  while (mor != r) {
    if (mor < r)
      add(++mor);
    else
      remove(mor--);
  }
  while (mol != l) {
    if (l < mol)
      add(--mol);
    else
      remove(mol++);
  }
  return K[k];
}
int main() {
  scanf("%d %d", &n, &q);
  sq = sqrt(n);
  for (int i = 1; i <= n; i++) scanf("%d", &ara[i]);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(1, 0);
  for (int i = 0; i < q; i++) {
    int node, num;
    scanf("%d %d", &node, &num);
    Q[i].l = st[node];
    Q[i].r = ed[node];
    Q[i].k = num;
    Q[i].id = i;
  }
  sort(Q, Q + q, cmp);
  for (int i = 0; i < q; i++) {
    answer[Q[i].id] = MO(i);
  }
  for (int i = 0; i < q; i++) {
    printf("%d\n", answer[i]);
  }
}
