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 std::cin;
using std::cout;
using std::endl;
using std::max;
using std::min;
using std::multiset;
using std::pair;
using std::priority_queue;
using std::queue;
using std::sort;
using std::vector;
const int maxN = 100000 + 233;
const int maxC = 100000 + 233;
const int maxQ = 100000 + 233;
const int NODE = 6000000 + 233;
int n, m, sz[maxN], col[maxN];
vector<int> G[maxN];
vector<int> Q[maxN];
int qv[maxQ], qk[maxQ], qa[maxQ];
void dfs_size(int u, int fa) {
  if (u != 1) {
    for (vector<int>::iterator it = G[u].begin(); it != G[u].end(); ++it) {
      if (*it == fa) {
        G[u].erase(it);
        break;
      }
    }
  }
  sz[u] = 1;
  for (int v : G[u]) {
    dfs_size(v, u);
    sz[u] += sz[v];
  }
}
bool cmp(int x, int y) { return sz[x] > sz[y]; }
void initialize() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &col[i]);
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &qv[i], &qk[i]);
    qa[i] = -1;
    Q[qv[i]].push_back(i);
  }
  dfs_size(1, -1);
  for (int u = 1; u <= n; ++u) std::sort(G[u].begin(), G[u].end(), cmp);
}
namespace SegmentTree {
int stk[NODE], stk_top = 0;
struct Node;
Node *nil;
struct Node {
  int s;
  Node *lson, *rson;
  Node(int s = 0) : s(s), lson(nil), rson(nil) {}
  void print() {
    printf("%lld : size = %d, ch = {%lld, %lld}\n", this - nil, s, lson - nil,
           rson - nil);
  }
} nodes[NODE];
void init() {
  for (int i = 1; i < NODE; ++i) stk[i] = i;
  stk_top = NODE - 1;
  nil = nodes;
  *nil = Node();
}
Node *alloc() {
  nodes[stk[stk_top]] = Node();
  return &nodes[stk[stk_top--]];
}
void disp(Node *o) { stk[++stk_top] = o - nil; }
vector<pair<int, int> > changes;
void dig(Node *o, int L, int R) {
  if (L == R) {
    changes.push_back(pair<int, int>(0, o->s));
  } else {
    int M = (L + R) >> 1;
    if (o->lson->s) dig(o->lson, L, M);
    if (o->rson->s) dig(o->rson, M + 1, R);
  }
}
Node *merge(Node *x, Node *y, int L, int R) {
  if (y == nil)
    return x;
  else if (x == nil) {
    dig(y, L, R);
    return y;
  } else {
    Node *o = alloc();
    o->s = x->s + y->s;
    if (L == R) {
      changes.push_back(pair<int, int>(x->s, o->s));
    } else {
      int M = (L + R) >> 1;
      o->lson = merge(x->lson, y->lson, L, M);
      o->rson = merge(x->rson, y->rson, M + 1, R);
    }
    disp(x);
    disp(y);
    return o;
  }
}
int post_sum(Node *o, int L, int R, int pos) {
  int ret = 0;
  while (o != nil && L < R) {
    int M = (L + R) >> 1;
    if (pos <= M)
      ret += o->rson->s, R = M, o = o->lson;
    else
      L = M + 1, o = o->rson;
  }
  if (L == R) ret += o->s;
  return ret;
}
void modify(Node *&root, int L, int R, int p, int v) {
  if (root == nil) root = alloc();
  Node *o = root;
  while (L < R) {
    o->s += v;
    int M = (L + R) >> 1;
    if (p <= M) {
      R = M;
      if (o->lson == nil) o->lson = alloc();
      o = o->lson;
    } else {
      L = M + 1;
      if (o->rson == nil) o->rson = alloc();
      o = o->rson;
    }
  }
  changes.push_back(pair<int, int>(o->s, o->s + v));
  o->s += v;
}
multiset<int> dfs(Node *o, int L, int R) {
  multiset<int> S;
  S.clear();
  if (o == nil)
    return S;
  else {
    int M = (L + R) >> 1;
    multiset<int> T;
    T = dfs(o->lson, L, M);
    S.insert(T.begin(), T.end());
    T = dfs(o->rson, M + 1, R);
    S.insert(T.begin(), T.end());
    if (L == R)
      for (int i = 0; i < o->s; ++i) S.insert(L);
    return S;
  }
}
}  // namespace SegmentTree
using namespace SegmentTree;
typedef pair<Node *, Node *> pnn;
pnn dfs(int u) {
  Node *rt = nil, *ct = nil;
  vector<pair<int, int> > mods;
  changes.clear();
  int cnt = 0;
  for (int v : G[u]) {
    if (++cnt == 1) {
      pnn np = dfs(v);
      rt = np.first;
      ct = np.second;
    } else {
      pnn np = dfs(v);
      changes.clear();
      ct = merge(ct, np.second, 1, maxC);
      mods.insert(mods.end(), changes.begin(), changes.end());
    }
  }
  changes.clear();
  modify(ct, 1, maxN, col[u], 1);
  mods.insert(mods.end(), changes.begin(), changes.end());
  for (pair<int, int> &p : mods)
    if (p.first != p.second) {
      if (p.first) modify(rt, 1, maxN, p.first, -1);
      if (p.second) modify(rt, 1, maxN, p.second, +1);
    }
  for (int i : Q[u]) {
    qa[i] = post_sum(rt, 1, maxN, qk[i]);
  }
  return pnn(rt, ct);
}
void solve() {
  init();
  dfs(1);
}
void print_ans() {
  for (int i = 1; i <= m; ++i) printf("%d\n", qa[i]);
}
int main() {
  initialize();
  solve();
  print_ans();
  return 0;
}