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 comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-8;
inline int II() {
  int n = 0, ch = getchar();
  bool t = 0;
  if (ch == -1) return 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') t = 1;
  for (; ch >= '0' && ch <= '9'; n = n * 10 + ch - '0', ch = getchar())
    ;
  if (t) return -n;
  return n;
}
inline void OO(int a) {
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  if (a >= 10) OO(a / 10);
  putchar(a % 10 + '0');
}
inline int sgn(double x) { return (x > EPS) - (x < -EPS); }
struct EE {
  int v, nx;
} E[100005 * 2];
int hd[100005], EN;
void init_edge(int num) {
  EN = 0;
  memset(hd, -1, num << 2);
}
void add_edge(int u, int v) {
  E[EN].v = v;
  E[EN].nx = hd[u];
  hd[u] = EN++;
  E[EN].v = u;
  E[EN].nx = hd[v];
  hd[v] = EN++;
}
vector<pair<int, int> > Q[100005];
int col[100005], cnt[100005], st[100005], ed[100005], dfn[100005], tot;
int sz[100005];
void dfs(int u, int par) {
  sz[u] = 1;
  dfn[++tot] = u;
  st[u] = tot;
  for (int k = hd[u]; ~k; k = E[k].nx) {
    int v = E[k].v;
    if (v == par) continue;
    dfs(v, u);
    sz[u] += sz[v];
  }
  ed[u] = tot;
}
int sum[100005], ans[100005];
void ins(int u) {
  for (int i = st[u]; i <= ed[u]; ++i) {
    ++sum[++cnt[col[dfn[i]]]];
  }
}
void del(int u) {
  for (int i = st[u]; i <= ed[u]; ++i) {
    --sum[cnt[col[dfn[i]]]--];
  }
}
void query(int u) {
  int z = Q[u].size();
  for (int i = 0; i < z; ++i) {
    ans[Q[u][i].first] = sum[Q[u][i].second];
  }
}
void calc(int u, int par, bool keep) {
  int mx = -1, child = -1;
  for (int k = hd[u]; ~k; k = E[k].nx) {
    int v = E[k].v;
    if (v != par && sz[v] > mx) mx = sz[v], child = v;
  }
  for (int k = hd[u]; ~k; k = E[k].nx) {
    int v = E[k].v;
    if (v != par && v != child) calc(v, u, 0);
  }
  if (child != -1) calc(child, u, 1);
  for (int k = hd[u]; ~k; k = E[k].nx) {
    int v = E[k].v;
    if (v != par && v != child) ins(v);
  }
  ++sum[++cnt[col[u]]];
  query(u);
  if (keep == 0) del(u);
}
int main() {
  int n, m, u, v, k;
  n = II();
  m = II();
  for (int i = 1; i <= n; ++i) col[i] = II();
  init_edge(n + 3);
  for (int i = 1; i <= n - 1; ++i) {
    u = II();
    v = II();
    add_edge(u, v);
  }
  for (int i = 1; i <= m; ++i) {
    v = II();
    k = II();
    Q[v].push_back(make_pair(i, k));
  }
  dfs(1, 0);
  calc(1, 0, 1);
  for (int i = 1; i <= m; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}