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;
struct Node {
  Node *ch[2];
  int r, s, v;
  Node(int _v = 0) : v(_v) {
    ch[0] = ch[1] = NULL;
    r = rand();
    s = 1;
  }
  void up() {
    s = 1;
    if (ch[0] != NULL) s += ch[0]->s;
    if (ch[1] != NULL) s += ch[1]->s;
  }
};
struct Treap {
  Node *root;
  Treap() { root = NULL; }
  void rot(Node *&o, int d) {
    Node *k = o->ch[d ^ 1];
    o->ch[d ^ 1] = k->ch[d];
    k->ch[d] = o;
    o->up();
    k->up();
    o = k;
  }
  void ins(Node *&o, int x) {
    if (o == NULL) {
      o = new Node(x);
      return;
    }
    int d = x >= o->v;
    ins(o->ch[d], x);
    if (o->r < o->ch[d]->r) rot(o, d ^ 1);
    o->up();
  }
  void del(Node *&o, int x) {
    if (o == NULL) return;
    if (o->v == x) {
      if (o->ch[0] != NULL && o->ch[1] != NULL) {
        int d = o->ch[0]->r > o->ch[1]->r;
        rot(o, d);
        del(o->ch[d], x);
      } else {
        Node *u = o;
        if (o->ch[0] == NULL)
          o = o->ch[1];
        else
          o = o->ch[0];
        delete u;
      }
    } else {
      int d = x > o->v;
      del(o->ch[d], x);
    }
    if (o != NULL) o->up();
  }
  void insert(int x) { ins(root, x); }
  void erase(int x) { del(root, x); }
  int query(int k) {
    Node *t = root;
    int ans = 0;
    while (1) {
      if (t == NULL) return ans;
      if (t->v >= k) {
        ans++;
        if (t->ch[1] != NULL) ans += t->ch[1]->s;
        t = t->ch[0];
      } else
        t = t->ch[1];
    }
  }
};
const int maxn = 200200;
int head[maxn], tol, val[maxn];
struct Edge {
  int next, to;
} edge[3 * maxn];
void addedge(int u, int v) {
  edge[tol].to = v;
  edge[tol].next = head[u];
  head[u] = tol++;
}
map<int, int> mp[maxn];
Treap *col[maxn];
vector<pair<int, int> > query[maxn];
int ans[maxn];
void dfs(int u, int fa) {
  mp[u][val[u]] = 1;
  col[u]->insert(1);
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (v == fa) continue;
    dfs(v, u);
    if (mp[u].size() < mp[v].size()) {
      std::swap(col[u], col[v]);
      std::swap(mp[u], mp[v]);
    }
    for (map<int, int>::iterator it = mp[v].begin(); it != mp[v].end(); it++) {
      if (mp[u].count(it->first) == 0) {
        mp[u][it->first] = it->second;
        col[u]->insert(it->second);
      } else {
        col[u]->erase(mp[u][it->first]);
        mp[u][it->first] += it->second;
        col[u]->insert(mp[u][it->first]);
      }
    }
  }
  for (vector<pair<int, int> >::iterator it = query[u].begin();
       it != query[u].end(); it++)
    ans[it->first] = col[u]->query(it->second);
}
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    memset(head, -1, sizeof(head));
    tol = 0;
    for (int i = 1; i <= n; i++) scanf("%d", &val[i]);
    for (int i = 1; i < n; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      addedge(a, b);
      addedge(b, a);
    }
    for (int i = 1; i <= n; i++) query[i].clear();
    for (int i = 1; i <= m; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      query[a].push_back(make_pair(i, b));
    }
    for (int i = 1; i <= n; i++) mp[i].clear();
    for (int i = 1; i <= n; i++) col[i] = new Treap();
    dfs(1, -1);
    for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  }
  return 0;
}