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>
#pragma GCC optimize("O3")
using namespace std;
const int N = 1e5 + 5;
int st[N];
int en[N];
vector<int> g[N];
int arr[N];
int color[N];
int sol[N];
int freq[N];
int BIT[N];
int pos = 0;
int bs = 350;
void dfs(int node, int parent) {
  st[node] = pos;
  arr[pos++] = node;
  for (auto &newNode : g[node]) {
    if (newNode != parent) {
      dfs(newNode, node);
    }
  }
  en[node] = pos - 1;
}
class query {
 public:
  int l, r, pos, k;
  query(int l, int r, int pos, int k) {
    this->l = l;
    this->r = r;
    this->pos = pos;
    this->k = k;
  }
};
void update(int x, int delta) {
  for (; x < N; x += x & -x) BIT[x] += delta;
}
int qry(int x) {
  int sum = 0;
  for (; x > 0; x -= x & -x) sum += BIT[x];
  return sum;
}
void add(int pos) {
  int c = color[arr[pos]];
  if (freq[c]) update(freq[c], -1);
  freq[c]++;
  update(freq[c], 1);
}
void remove(int pos) {
  int c = color[arr[pos]];
  update(freq[c], -1);
  freq[c]--;
  if (freq[c]) update(freq[c], 1);
}
int get_ans(int k) { return qry(N - 1) - qry(k - 1); }
bool cmp(query q1, query q2) {
  int b1 = q1.l / bs, b2 = q2.l / bs;
  if (b1 < b2)
    return true;
  else if (b1 > b2)
    return false;
  else {
    if (b1 % 2 == 0) {
      if (q1.r < q2.r)
        return true;
      else if (q1.r > q2.r)
        return false;
      else
        return q1.pos < q2.pos;
    } else {
      if (q1.r < q2.r)
        return false;
      else if (q1.r > q2.r)
        return true;
      else
        return q1.pos < q2.pos;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> color[i];
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  vector<query> queries;
  for (int i = 1; i <= m; i++) {
    int v, k;
    cin >> v >> k;
    queries.push_back(query(st[v], en[v], i, k));
  }
  sort(queries.begin(), queries.end(), cmp);
  int l = 0, r = 0;
  add(0);
  for (auto &q : queries) {
    int curL = q.l, curR = q.r, curP = q.pos, curK = q.k;
    while (l > curL) {
      add(--l);
    }
    while (r < curR) {
      add(++r);
    }
    while (l < curL) {
      remove(l++);
    }
    while (r > curR) {
      remove(r--);
    }
    sol[curP] = get_ans(curK);
  }
  for (int i = 1; i <= m; i++) cout << sol[i] << '\n';
  return 0;
}