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>
const int MAX_N = 1e5 + 1;
int ans[MAX_N], color[MAX_N];
std::vector<int> adj[MAX_N];
int l[MAX_N], r[MAX_N], newcolor[MAX_N], max_id = 0;
void DFS(int u, int parent) {
  l[u] = ++max_id;
  newcolor[l[u]] = color[u];
  for (int i = 0; i < (int)adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == parent) continue;
    DFS(v, u);
  }
  r[u] = max_id;
}
std::pair<int, std::pair<int, int> > qr[MAX_N];
int sqrtn;
bool cf(std::pair<int, std::pair<int, int> > a,
        std::pair<int, std::pair<int, int> > b) {
  int sa = (l[a.second.first] + sqrtn - 1) / sqrtn,
      sb = (l[b.second.first] + sqrtn - 1) / sqrtn;
  if (sa != sb)
    return sa < sb;
  else
    return r[a.second.first] < r[b.second.first];
}
int bit[MAX_N];
void bit_update(int pos, int val) {
  if (pos <= 0) return;
  for (; pos < MAX_N; pos += pos & (-pos)) bit[pos] += val;
}
int bit_query(int pos) {
  int ret = 0;
  for (; pos; pos -= pos & (-pos)) ret += bit[pos];
  return ret;
}
int count[MAX_N];
void add(int c) {
  bit_update(count[c], -1);
  count[c]++;
  bit_update(count[c], 1);
}
void remove(int c) {
  bit_update(count[c], -1);
  count[c]--;
  bit_update(count[c], 1);
}
int main() {
  int N, Q;
  scanf("%d %d", &N, &Q);
  for (int i = 1; i <= N; i++) scanf("%d", &color[i]);
  for (int i = 1; i < N; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= Q; i++) {
    qr[i].first = i;
    scanf("%d %d", &qr[i].second.first, &qr[i].second.second);
  }
  int root = 1;
  DFS(root, -1);
  sqrtn = std::sqrt(N);
  std::sort(qr + 1, qr + 1 + Q, cf);
  int L = 0, R = 0;
  for (int i = 1; i <= Q; i++) {
    while (L < l[qr[i].second.first]) remove(newcolor[L++]);
    while (L > l[qr[i].second.first]) add(newcolor[--L]);
    while (R < r[qr[i].second.first]) add(newcolor[++R]);
    while (R > r[qr[i].second.first]) remove(newcolor[R--]);
    ans[qr[i].first] =
        bit_query(MAX_N - 1) - bit_query(qr[i].second.second - 1);
  }
  for (int i = 1; i <= Q; i++) printf("%d\n", ans[i]);
  return 0;
}