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 MOD = 1e9 + 7;
bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }
int Set(int N, int pos) { return (N | (1 << pos)); }
int fx[] = {-1, 0, 1, 0};
int fy[] = {0, 1, 0, -1};
inline long long BigMod(long long B, long long P, long long M) {
  long long R = 1;
  while (P > 0) {
    if (P % 2 == 1) {
      R = (R * B) % M;
    }
    P /= 2;
    B = (B * B) % M;
  }
  return R;
}
const int N = 100000;
int n, q, sq, counter;
int color[N + 5], st[N + 5], ed[N + 5], cnt[N + 5], K[N + 5], ara[N + 5];
vector<int> G[N + 5];
void dfs(int node, int pre) {
  st[node] = ++counter;
  color[counter] = ara[node];
  for (int i : G[node])
    if (i != pre) dfs(i, node);
  ed[node] = counter;
}
struct data {
  int l, r, k, id;
};
bool cmp(data A, data B) {
  if (A.l / sq != B.l / sq) return A.l < B.l;
  return A.r < B.r;
}
data Q[N + 5];
int answer[N + 5];
int mol = 1, mor = 0;
void add(int pos) { ++K[++cnt[color[pos]]]; }
void remove(int pos) { K[cnt[color[pos]]--]--; }
int MO(int id) {
  int l = Q[id].l;
  int r = Q[id].r;
  int k = Q[id].k;
  while (mor != r) {
    if (mor < r)
      add(++mor);
    else
      remove(mor--);
  }
  while (mol != l) {
    if (l < mol)
      add(--mol);
    else
      remove(mol++);
  }
  return K[k];
}
int main() {
  scanf("%d %d", &n, &q);
  sq = sqrt(n);
  for (int i = 1; i <= n; i++) scanf("%d", &ara[i]);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(1, 0);
  for (int i = 0; i < q; i++) {
    int node, num;
    scanf("%d %d", &node, &num);
    Q[i].l = st[node];
    Q[i].r = ed[node];
    Q[i].k = num;
    Q[i].id = i;
  }
  sort(Q, Q + q, cmp);
  for (int i = 0; i < q; i++) {
    answer[Q[i].id] = MO(i);
  }
  for (int i = 0; i < q; i++) {
    printf("%d\n", answer[i]);
  }
}