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 maxN = 100001;
long long int BLK = 500;
vector<long long int> v[maxN];
long long int a[maxN], start[maxN], e[maxN], timer, ft[2 * maxN];
long long int nodeF[maxN], eleF[maxN], FF[maxN] = {0}, ans[maxN];
long long int bucket[maxN], n, q, sz;
struct query {
  long long int l, r, ind, k;
};
query Q[maxN];
long long int getBLK(long long int n) { return (n + BLK - 1) / BLK; }
void dfs(long long int n, long long int p) {
  ft[timer] = n;
  start[n] = timer;
  timer++;
  for (auto i : v[n]) {
    if (i != p) {
      dfs(i, n);
    }
  }
  e[n] = timer;
  ft[timer] = n;
  timer++;
}
void add(long long int inx) {
  long long int node = ft[inx];
  long long int col = a[node];
  nodeF[node]++;
  if (nodeF[node] == 2) {
    eleF[col]++;
    FF[eleF[col]]++;
    bucket[getBLK(eleF[col])]++;
    FF[eleF[col] - 1]--;
    bucket[getBLK(eleF[col] - 1)]--;
  }
}
void remove(long long int inx) {
  long long int node = ft[inx];
  long long int col = a[node];
  nodeF[node]--;
  if (nodeF[node] == 1) {
    eleF[col]--;
    FF[eleF[col]]++;
    bucket[getBLK(eleF[col])]++;
    FF[eleF[col] + 1]--;
    bucket[getBLK(eleF[col] + 1)]--;
  }
}
bool comp(query a, query b) {
  if (a.l / BLK != b.l / BLK) {
    return a.l / BLK < b.l / BLK;
  }
  if (a.l / BLK % 2)
    return a.r < b.r;
  else
    return a.r > b.r;
}
long long int getans(long long int k, long long int n) {
  long long int ans = 0;
  long long int L = getBLK(k);
  long long int R = getBLK(n);
  if (L == R) {
    for (long long int i = k; i < n + 1; i++) ans += FF[i];
    return ans;
  }
  for (long long int i = k; i <= L * BLK; i++) {
    ans += FF[i];
  }
  for (long long int i = L + 1; i < R; i++) ans += bucket[i];
  for (long long int i = R * BLK + 1; i < n + 1; i++) ans += FF[i];
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> q;
  for (long long int i = 1; i < n + 1; i++) cin >> a[i];
  for (long long int i = 0; i < n - 1; i++) {
    long long int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  timer = 1;
  dfs(1, -1);
  for (long long int i = 1; i <= q; i++) {
    long long int a, k;
    cin >> a >> k;
    Q[i].l = start[a];
    Q[i].r = e[a];
    Q[i].k = k;
    Q[i].ind = i;
  }
  sort(Q + 1, Q + q + 1, comp);
  long long int ML = 0, MR = -1;
  for (long long int i = 1; i < q + 1; i++) {
    long long int L = Q[i].l;
    long long int R = Q[i].r;
    long long int ind = Q[i].ind;
    long long int k = Q[i].k;
    while (ML > L) {
      ML--;
      add(ML);
    }
    while (MR < R) {
      MR++;
      add(MR);
    }
    while (ML < L) {
      remove(ML);
      ML++;
    }
    while (MR > R) {
      remove(MR);
      MR--;
    }
    ans[ind] = getans(k, n);
  }
  for (long long int i = 1; i < q + 1; i++) cout << ans[i] << "\n";
}
long long int power(long long int x, long long int y) {
  long long int res = 1;
  x %= 1000000007;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res % 1000000007;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}