#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-8;
inline int II() {
  int n = 0, ch = getchar();
  bool t = 0;
  if (ch == -1) return 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') t = 1;
  for (; ch >= '0' && ch <= '9'; n = n * 10 + ch - '0', ch = getchar())
    ;
  if (t) return -n;
  return n;
}
inline void OO(int a) {
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  if (a >= 10) OO(a / 10);
  putchar(a % 10 + '0');
}
inline int sgn(double x) { return (x > EPS) - (x < -EPS); }
struct EE {
  int v, nx;
} E[100005 * 2];
int hd[100005], EN;
void init_edge(int num) {
  EN = 0;
  memset(hd, -1, num << 2);
}
void add_edge(int u, int v) {
  E[EN].v = v;
  E[EN].nx = hd[u];
  hd[u] = EN++;
  E[EN].v = u;
  E[EN].nx = hd[v];
  hd[v] = EN++;
}
vector<pair<int, int> > Q[100005];
int col[100005], cnt[100005], st[100005], ed[100005], dfn[100005], tot;
int sz[100005];
void dfs(int u, int par) {
  sz[u] = 1;
  dfn[++tot] = u;
  st[u] = tot;
  for (int k = hd[u]; ~k; k = E[k].nx) {
    int v = E[k].v;
    if (v == par) continue;
    dfs(v, u);
    sz[u] += sz[v];
  }
  ed[u] = tot;
}
int sum[100005], ans[100005];
void ins(int u) {
  for (int i = st[u]; i <= ed[u]; ++i) {
    ++sum[++cnt[col[dfn[i]]]];
  }
}
void del(int u) {
  for (int i = st[u]; i <= ed[u]; ++i) {
    --sum[cnt[col[dfn[i]]]--];
  }
}
void query(int u) {
  int z = Q[u].size();
  for (int i = 0; i < z; ++i) {
    ans[Q[u][i].first] = sum[Q[u][i].second];
  }
}
void calc(int u, int par, bool keep) {
  int mx = -1, child = -1;
  for (int k = hd[u]; ~k; k = E[k].nx) {
    int v = E[k].v;
    if (v != par && sz[v] > mx) mx = sz[v], child = v;
  }
  for (int k = hd[u]; ~k; k = E[k].nx) {
    int v = E[k].v;
    if (v != par && v != child) calc(v, u, 0);
  }
  if (child != -1) calc(child, u, 1);
  for (int k = hd[u]; ~k; k = E[k].nx) {
    int v = E[k].v;
    if (v != par && v != child) ins(v);
  }
  ++sum[++cnt[col[u]]];
  query(u);
  if (keep == 0) del(u);
}
int main() {
  int n, m, u, v, k;
  n = II();
  m = II();
  for (int i = 1; i <= n; ++i) col[i] = II();
  init_edge(n + 3);
  for (int i = 1; i <= n - 1; ++i) {
    u = II();
    v = II();
    add_edge(u, v);
  }
  for (int i = 1; i <= m; ++i) {
    v = II();
    k = II();
    Q[v].push_back(make_pair(i, k));
  }
  dfs(1, 0);
  calc(1, 0, 1);
  for (int i = 1; i <= m; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
