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;
const long long int block = 448;
vector<long long int> adj[100005];
long long int st[100005], en[100005], timer;
pair<pair<long long int, long long int>, long long int> qry[200005];
long long int cnt[100005];
long long int avb[100005];
long long int an[100005];
pair<long long int, long long int> a[100005];
long long int n, q, ans, k;
inline void dfs(long long int x, long long int pr) {
  st[x] = ++timer;
  for (auto i : adj[x])
    if (i != pr) dfs(i, x);
  en[x] = timer;
}
inline bool cmp_clr(pair<long long int, long long int> a,
                    pair<long long int, long long int> b) {
  return st[a.second] < st[b.second];
}
inline bool cmp(pair<pair<long long int, long long int>, long long int> a,
                pair<pair<long long int, long long int>, long long int> b) {
  long long int l1 = st[a.first.first], r1 = en[a.first.first];
  long long int l2 = st[b.first.first], r2 = en[b.first.first];
  if (l1 / block == l2 / block) return r1 < r2;
  return l1 / block < l2 / block;
}
inline void add(pair<long long int, long long int> val) {
  cnt[val.first]++;
  avb[cnt[val.first] - 1]--;
}
inline void remove(pair<long long int, long long int> val) {
  if (cnt[val.first] == 0) return;
  cnt[val.first]--;
  avb[cnt[val.first]]++;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> q;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  for (long long int i = 1; i < n; i++) {
    long long int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 1);
  sort(a + 1, a + 1 + n, cmp_clr);
  for (long long int i = 1; i <= q; i++) {
    long long int x, y;
    cin >> x >> y;
    qry[i].first.first = x, qry[i].first.second = y, qry[i].second = i;
  }
  sort(qry + 1, qry + 1 + q, cmp);
  long long int cur_l = 1, cur_r = 0;
  for (long long int i = 1; i <= q; i++) {
    long long int l = st[qry[i].first.first], r = en[qry[i].first.first];
    k = qry[i].first.second;
    while (cur_r < r) {
      cur_r++;
      add(a[cur_r]);
    }
    while (cur_r > r) {
      remove(a[cur_r]);
      cur_r--;
    }
    while (cur_l > l) {
      cur_l--;
      add(a[cur_l]);
    }
    while (cur_l < l) {
      remove(a[cur_l]);
      cur_l++;
    }
    an[qry[i].second] = avb[100004] - avb[k - 1];
  }
  for (long long int i = 1; i <= q; i++) cout << an[i] << '\n';
}