#include <bits/stdc++.h>
using namespace std;
int Ans[100001], C[100001], Arr[100001];
vector<int> Edge[100001];
vector<int> Queries[100001];
map<int, int> Map1[100001], Map2[100001];
void DFS(int Now, int Par) {
  Map1[Now][C[Now]]++;
  Map2[Now][1]++;
  for (auto i : Edge[Now]) {
    if (i == Par) continue;
    DFS(i, Now);
  }
  for (auto i : Edge[Now]) {
    if (i == Par) continue;
    if (Map1[Now].size() < Map1[i].size()) {
      Map1[Now].swap(Map1[i]);
      Map2[Now].swap(Map2[i]);
    }
  }
  for (auto i : Edge[Now]) {
    if (i == Par) continue;
    for (auto j : Map1[i]) {
      int X = Map1[Now][j.first];
      Map1[Now][j.first] += j.second;
      for (int k = 1; k <= j.second; ++k) Map2[Now][X + k]++;
    }
  }
  for (auto i : Queries[Now]) Ans[i] = Map2[Now][Arr[i]];
  return;
}
int main() {
  int N, Q;
  cin >> N >> Q;
  for (int i = 1; i <= N; ++i) cin >> C[i];
  for (int i = 1; i <= N - 1; ++i) {
    int A, B;
    cin >> A >> B;
    Edge[A].push_back(B);
    Edge[B].push_back(A);
  }
  for (int i = 1; i <= Q; ++i) {
    int A;
    cin >> A >> Arr[i];
    Queries[A].push_back(i);
  }
  DFS(1, -1);
  for (int i = 1; i <= Q; ++i) cout << Ans[i] << "\n";
  return 0;
}
