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;
int const N = 100000 + 10;
int ans[N], sum, a[N], c[N];
int n, m, block, root, id[N], size[N];
int ne[N << 1], to[N << 1], first[N], tot;
int num[N], tim[N];
void add(int u, int v) {
  ne[tot] = first[u];
  to[tot] = v;
  first[u] = tot++;
}
struct Node {
  int l, r, id, k;
  bool operator<(const Node& e) const {
    return l / block < e.l / block || l / block == e.l / block && r < e.r;
  }
} q[N];
int dfs(int u, int f) {
  id[u] = ++tot;
  size[u] = 1;
  for (int i = first[u]; ~i; i = ne[i]) {
    int v = to[i];
    if (v == f) continue;
    size[u] += dfs(v, u);
  }
  return size[u];
}
void Init() {
  root = 1;
  memset(first, -1, sizeof(first));
  scanf("%d%d", &n, &m);
  block = (int)ceil(pow(n, 0.5));
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
  }
  tot = 0;
  dfs(root, -1);
  for (int i = 1; i <= n; i++) a[id[i]] = c[i];
  for (int i = 1; i <= m; i++) {
    int v;
    scanf("%d%d", &v, &q[i].k);
    q[i].l = id[v];
    q[i].r = id[v] + size[v] - 1;
    q[i].id = i;
  }
  sort(q + 1, q + 1 + m);
}
void add(int pos) {
  num[a[pos]]++;
  tim[num[a[pos]]]++;
}
void del(int pos) {
  tim[num[a[pos]]]--;
  num[a[pos]]--;
}
int main() {
  Init();
  int L = 1, R = 0;
  for (int i = 1; i <= m; i++) {
    while (L < q[i].l) del(L++);
    while (L > q[i].l) add(--L);
    while (R < q[i].r) add(++R);
    while (R > q[i].r) del(R--);
    ans[q[i].id] = tim[q[i].k];
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}