#include <bits/stdc++.h>
using namespace std;
int n, color[100003], bit[100003], res[100003], cnt[100003], sz[100003];
bool big[100003];
void update(int idx, int val) {
  if (idx == 0) return;
  while (idx < 100003) {
    bit[idx] += val;
    idx += idx & (-idx);
  }
}
int query(int idx) {
  int res = 0;
  while (idx) {
    res += bit[idx];
    idx -= idx & (-idx);
  }
  return res;
}
vector<int> adj[100003];
vector<pair<int, int> > qs[100003];
void szdfs(int r = 1, int p = -1) {
  sz[r] = 1;
  for (auto &elem : adj[r])
    if (elem != p) szdfs(elem, r), sz[r] += sz[elem];
}
void add(int r, int p) {
  cnt[color[r]]++;
  update(cnt[color[r]], 1);
  update(cnt[color[r]] - 1, -1);
  for (auto &elem : adj[r]) {
    if (elem != p && !big[elem]) {
      add(elem, r);
    }
  }
}
void rem(int r, int p) {
  cnt[color[r]]--;
  update(cnt[color[r]] + 1, -1);
  update(cnt[color[r]], 1);
  for (auto &elem : adj[r]) {
    if (elem != p && !big[elem]) rem(elem, r);
  }
}
void go(int r = 1, int p = -1, bool keep = true) {
  int bigchild = -1, maxim = 0;
  for (auto &elem : adj[r]) {
    if (elem != p && sz[elem] > maxim) {
      maxim = sz[elem], bigchild = elem;
    }
  }
  for (auto &elem : adj[r]) {
    if (elem != p && elem != bigchild) {
      go(elem, r, false);
    }
  }
  if (bigchild != -1) go(bigchild, r, true), big[bigchild] = true;
  add(r, p);
  for (auto &elem : qs[r]) {
    res[elem.second] = query(n) - query(elem.first - 1);
  }
  if (bigchild != -1) {
    big[bigchild] = false;
  }
  if (!keep) rem(r, p);
}
int main() {
  int q, a, b;
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    color[i] = a;
  }
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &a, &b);
    adj[a].push_back(b), adj[b].push_back(a);
  }
  for (int i = 0; i < q; i++) {
    scanf("%d %d", &a, &b);
    qs[a].push_back({b, i});
  }
  szdfs();
  go();
  for_each(res, res + q, [](int &x) { printf("%d\n", x); });
  return 0;
}
