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 n, m, k, kk, i, o, pos[100000 + 10], kol[100000 + 10], c[100000 + 10],
    r[100000 + 10], t[500000 + 10], d[100000 + 10], tin[100000 + 10],
    tout[100000 + 10];
vector<int> a[100000 + 10];
struct my {
  int f;
  int s;
  int k;
  int o;
};
my b[100000 + 10];
void update(int pos, int val) {
  for (int i = pos; i <= n; i |= (i + 1)) {
    t[i] += val;
  }
}
int sum(int pos) {
  int ans = 0;
  for (int i = pos; i >= 0; i &= (i + 1), i--) {
    ans += t[i];
  }
  return ans;
}
int get(int l, int r) { return sum(r) - sum(l - 1); }
void dfs(int x, int pr = -1) {
  k++;
  tin[x] = k;
  pos[k] = x;
  for (int i = 0; i < a[x].size(); i++)
    if (pr != a[x][i]) dfs(a[x][i], x);
  tout[x] = k;
}
void add(int pos, int tr) {
  int o = c[pos];
  update(kol[o], -1);
  kol[o]++;
  update(kol[o], 1);
}
void del(int pos, int tr) {
  int o = c[pos];
  update(kol[o], -1);
  kol[o]--;
  update(kol[o], 1);
}
bool cmp(my a, my b) {
  if (a.f / kk != b.f / kk) {
    if (a.f < b.f) return true;
    return false;
  }
  if (a.s < b.s) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  kk = sqrt(n);
  for (i = 1; i <= n; i++) cin >> c[i];
  for (i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  dfs(1);
  for (i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    b[i].f = tin[x];
    b[i].s = tout[x];
    b[i].k = i;
    b[i].o = y;
  }
  sort(b + 1, b + m + 1, cmp);
  int x = b[1].f, y = b[1].s;
  for (i = x; i <= y; i++) add(pos[i], b[1].o);
  r[b[1].k] = get(b[1].o, n);
  for (i = 2; i <= m; i++) {
    for (; x > b[i].f;) {
      add(pos[x - 1], b[i].o);
      x--;
    }
    for (; y < b[i].s;) {
      add(pos[y + 1], b[i].o);
      y++;
    }
    for (; x < b[i].f;) {
      del(pos[x], b[i].o);
      x++;
    }
    for (; y > b[i].s;) {
      del(pos[y], b[i].o);
      y--;
    }
    r[b[i].k] = get(b[i].o, n);
  }
  for (i = 1; i <= m; i++) cout << r[i] << "\n";
}