Problem: You have a rooted tree consisting of n vertices. Each vertex of the tree has some color. We will assume that the tree vertices are numbered by integers from 1 to n. Then we represent the color of vertex v as cv. The tree root is a vertex with number 1.

In this problem you need to answer to m queries. Each query is described by two integers vj, kj. The answer to query vj, kj is the number of such colors of vertices x, that the subtree of vertex vj contains at least kj vertices of color x.

You can find the definition of a rooted tree by the following link: http://en.wikipedia.org/wiki/Tree_(graph_theory).

Input

The first line contains two integers n and m (2 ≤ n ≤ 105; 1 ≤ m ≤ 105). The next line contains a sequence of integers c1, c2, ..., cn (1 ≤ ci ≤ 105). The next n - 1 lines contain the edges of the tree. The i-th line contains the numbers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi) — the vertices connected by an edge of the tree.

Next m lines contain the queries. The j-th line contains two integers vj, kj (1 ≤ vj ≤ n; 1 ≤ kj ≤ 105).

Output

Print m integers — the answers to the queries in the order the queries appear in the input.

Examples

Input

8 5
1 2 2 3 3 2 3 3
1 2
1 5
2 3
2 4
5 6
5 7
5 8
1 2
1 3
1 4
2 3
5 3


Output

2
2
1
0
1


Input

4 1
1 2 3 4
1 2
2 3
3 4
1 1


Output

4

Note

A subtree of vertex v in a rooted tree with root r is a set of vertices {u : dist(r, v) + dist(v, u) = dist(r, u)}. Where dist(x, y) is the length (in edges) of the shortest path between vertices x and y.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int dx[8] = {1, -1, 0, 0, -1, -1, 1, 1};
int dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
const long long inf = 1000000007;
vector<int> adj[200010], vis(200010, 0), dis(200010, 0), fin(200010, 0),
    col(200010, 0), res(200010, 0);
int myrandom(int i) { return std::rand() % i; }
int t = 1;
int bit[200010];
void dfs(int a) {
  vis[a] = 1;
  dis[a] = t;
  res[t] = col[a];
  t++;
  for (auto i : adj[a]) {
    if (vis[i] == 0) {
      dfs(i);
    }
  }
  fin[a] = t;
}
inline long long hilbertOrder(long long x, long long y, long long pow,
                              long long rotate) {
  if (pow == 0) {
    return 0;
  }
  long long hpow = 1 << (pow - 1);
  long long seg = (x < hpow) ? ((y < hpow) ? 0 : 3) : ((y < hpow) ? 1 : 2);
  seg = (seg + rotate) & 3;
  const long long rotateDelta[4] = {3, 0, 0, 1};
  long long nx = x & (x ^ hpow), ny = y & (y ^ hpow);
  long long nrot = (rotate + rotateDelta[seg]) & 3;
  long long subSquareSize = 1ll << (2 * pow - 2);
  long long ans = seg * subSquareSize;
  long long add = hilbertOrder(nx, ny, pow - 1, nrot);
  ans += (seg == 1 || seg == 2) ? add : (subSquareSize - add - 1);
  return ans;
}
struct Query {
  long long l, r, idx, val;
  long long ord;
  inline void calcOrder() { ord = hilbertOrder(l, r, 21, 0); }
};
inline bool operator<(const Query &a, const Query &b) { return a.ord < b.ord; }
void update(int id, int delta) {
  while (id <= 100000) {
    bit[id] += delta;
    id += id & -id;
  }
}
int get_sum(int id) {
  int res = 0;
  while (id) {
    res += bit[id];
    id -= id & -id;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  memset(bit, 0, sizeof(bit));
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> col[i];
  }
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1);
  vector<Query> v(m);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[i].l = dis[a];
    v[i].r = fin[a] - 1;
    v[i].idx = i;
    v[i].val = b;
    v[i].calcOrder();
  }
  sort((v).begin(), (v).end());
  vector<int> ans(m + 1, 0);
  vector<int> cnt(100010, 0);
  int l = 1, r = n;
  for (int i = 1; i <= n; i++) {
    cnt[res[i]]++;
  }
  for (int i = 1; i <= 100000; i++) {
    if (cnt[i] > 0) {
      update(cnt[i], 1);
    }
  }
  for (int i = 0; i < m; i++) {
    while (l > v[i].l) {
      if (cnt[res[l - 1]]) update(cnt[res[l - 1]], -1);
      update(cnt[res[l - 1]] + 1, 1);
      cnt[res[l - 1]]++;
      l--;
    }
    while (r < v[i].r) {
      if (cnt[res[r + 1]]) update(cnt[res[r + 1]], -1);
      update(cnt[res[r + 1]] + 1, 1);
      cnt[res[r + 1]]++;
      r++;
    }
    while (l < v[i].l) {
      update(cnt[res[l]], -1);
      cnt[res[l]]--;
      if (cnt[res[l]]) update(cnt[res[l]], 1);
      l++;
    }
    while (r > v[i].r) {
      update(cnt[res[r]], -1);
      cnt[res[r]]--;
      if (cnt[res[r]]) update(cnt[res[r]], 1);
      r--;
    }
    int sum = get_sum(100000) - get_sum(v[i].val - 1);
    ans[v[i].idx] = sum;
  }
  for (int i = 0; i < m; i++) {
    cout << ans[i] << '\n';
  }
}