#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int m, n, c[N], cnt[N];
vector<int> g[N];
int bit[N];
void add(int x, int t) {
  for (; x <= n; x += x & -x) bit[x] += t;
}
int ask(int x) {
  int ret = 0;
  for (; x > 0; x -= x & -x) ret += bit[x];
  return ret;
}
struct Que {
  int p, c, ret;
} q[N];
vector<int> geet[N];
int st[N], ed[N], clk, sz[N], son[N], mat[N];
void predfs(int u, int f) {
  st[u] = ++clk, mat[clk] = u, son[u] = -1, sz[u] = 1;
  for (int i = 0; i < (int)g[u].size(); ++i) {
    int v = g[u][i];
    if (v == f) continue;
    predfs(v, u);
    sz[u] += sz[v];
    if (son[u] == -1 || sz[v] > sz[son[u]]) son[u] = v;
  }
  ed[u] = clk;
}
void dfs(int u, int f, bool keep) {
  for (int i = 0; i < (int)g[u].size(); ++i) {
    int v = g[u][i];
    if (v == f || v == son[u]) continue;
    dfs(v, u, 0);
  }
  if (son[u] != -1) dfs(son[u], u, 1);
  ++cnt[c[u]];
  if (cnt[c[u]] - 1 > 0) add(cnt[c[u]] - 1, -1);
  add(cnt[c[u]], 1);
  for (int i = 0; i < (int)g[u].size(); ++i) {
    int v = g[u][i];
    if (v == f || v == son[u]) continue;
    for (int j = st[v]; j <= ed[v]; ++j) {
      ++cnt[c[mat[j]]];
      if (cnt[c[mat[j]]] - 1 > 0) add(cnt[c[mat[j]]] - 1, -1);
      add(cnt[c[mat[j]]], 1);
    }
  }
  for (int i = 0; i < (int)geet[u].size(); ++i) {
    int id = geet[u][i];
    q[id].ret = ask(n) - ask(min(n, q[id].p - 1));
  }
  if (!keep) {
    for (int i = st[u]; i <= ed[u]; ++i) {
      add(cnt[c[mat[i]]], -1);
      --cnt[c[mat[i]]];
      if (cnt[c[mat[i]]]) add(cnt[c[mat[i]]], 1);
    }
  }
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &c[i]);
    }
    for (int i = 0; i < N; ++i) g[i].clear(), geet[i].clear();
    memset(bit, 0, sizeof(bit));
    memset(cnt, 0, sizeof(cnt));
    clk = 0;
    for (int i = 1; i < n; ++i) {
      int u, v;
      scanf("%d%d", &u, &v);
      g[u].push_back(v);
      g[v].push_back(u);
    }
    predfs(1, 0);
    for (int i = 1; i <= m; ++i) {
      int u;
      scanf("%d%d", &u, &q[i].p);
      geet[u].push_back(i);
    }
    dfs(1, 0, 1);
    for (int i = 1; i <= m; ++i) {
      printf("%d\n", q[i].ret);
    }
  }
  return 0;
}
