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:16777216")
using namespace std;
const long double pi = acos(-1.0);
const long double eps = 1e-6;
const int INF = 1E9;
const int MAXN = 5111;
struct node {
  pair<int, int> key;
  int pr, cnt;
  node *l, *r;
  node(pair<int, int> _key) {
    key = _key;
    pr = rand();
    cnt = 1;
    l = r = NULL;
  }
};
int cnt(node *p) { return p ? p->cnt : 0; }
void upd_cnt(node *&p) {
  if (p) p->cnt = 1 + cnt(p->l) + cnt(p->r);
}
void split(node *p, pair<int, int> key, node *&l, node *&r) {
  if (p == NULL) {
    l = r = NULL;
    return;
  }
  if (key < p->key) {
    split(p->l, key, l, p->l);
    r = p;
  } else {
    split(p->r, key, p->r, r);
    l = p;
  }
  upd_cnt(p);
}
void merge(node *&p, node *l, node *r) {
  if (l == NULL)
    p = r;
  else if (r == NULL)
    p = l;
  else if (l->pr < r->pr) {
    p = l;
    merge(l->r, l->r, r);
  } else {
    p = r;
    merge(r->l, l, r->l);
  }
  upd_cnt(p);
}
void insert(pair<int, int> key, int pr, node *&p) {
  if (p == NULL) {
    p = new node(key);
    p->pr = pr;
    return;
  }
  if (pr > p->pr) {
    if (key > p->key)
      insert(key, pr, p->r);
    else
      insert(key, pr, p->l);
  } else {
    node *t = new node(key);
    t->pr = pr;
    split(p, key, t->l, t->r);
    p = t;
  }
  upd_cnt(p);
}
void erase(pair<int, int> key, node *&p) {
  if (p == NULL) return;
  if (p->key == key)
    merge(p, p->l, p->r);
  else {
    if (key < p->key)
      erase(key, p->l);
    else
      erase(key, p->r);
  }
  upd_cnt(p);
}
int n, m;
vector<int> color, used;
vector<vector<int> > g, queries;
vector<pair<int, int> > q;
vector<node *> root;
vector<map<int, int> > lib;
vector<int> ans, link;
void init() {
  color.resize(n);
  used.resize(n, 0);
  root.resize(n, NULL);
  g.resize(n);
  queries.resize(n);
  q.resize(m);
  ans.resize(m);
  link.resize(n);
  lib.resize(n);
}
void intersect(int vid, int wid, node *&w) {
  if (!w) return;
  if (w->l) intersect(vid, wid, w->l);
  if (w->r) intersect(vid, wid, w->r);
  int ckey = w->key.second;
  if (lib[link[vid]].find(ckey) == lib[link[vid]].end()) {
    lib[link[vid]][ckey] = w->key.first;
    insert(w->key, rand(), root[vid]);
  } else {
    erase(make_pair(lib[link[vid]][ckey], ckey), root[vid]);
    w->key.first += lib[link[vid]][ckey];
    insert(w->key, rand(), root[vid]);
    lib[link[vid]][ckey] = w->key.first;
  }
  lib[link[wid]].erase(ckey);
  delete w;
}
void dfs(int v, int par) {
  used[v] = 1;
  for (int i = 0; i < (int)(g[v].size()); i++) {
    int w = g[v][i];
    if (!used[w]) {
      dfs(w, v);
    }
  }
  if (v == 0) {
    v = v;
  }
  int maxid = -1;
  for (int i = 0; i < (int)(g[v].size()); i++) {
    int w = g[v][i];
    if (w != par) {
      if (maxid == -1 || cnt(root[w]) > cnt(root[maxid])) maxid = w;
    }
  }
  if (maxid != -1) {
    link[v] = link[maxid];
    root[v] = root[maxid];
    for (int i = 0; i < (int)(g[v].size()); i++) {
      int w = g[v][i];
      if (w != par && w != maxid) {
        intersect(v, w, root[w]);
      }
    }
    if (lib[link[v]].find(color[v]) == lib[link[v]].end()) {
      lib[link[v]][color[v]] = 1;
      insert(make_pair(1, color[v]), rand(), root[v]);
    } else {
      erase(make_pair(lib[link[v]][color[v]], color[v]), root[v]);
      lib[link[v]][color[v]]++;
      insert(make_pair(lib[link[v]][color[v]], color[v]), rand(), root[v]);
    }
  } else {
    root[v] = new node(make_pair(1, color[v]));
    link[v] = v;
    lib[link[v]][color[v]] = 1;
  }
  node *t1 = NULL, *t2 = NULL;
  for (int i = 0; i < queries[v].size(); i++) {
    int qid = queries[v][i];
    split(root[v], make_pair(q[qid].second, 0), t1, t2);
    ans[qid] = cnt(t2);
    merge(root[v], t1, t2);
  }
}
int main() {
  cin >> n >> m;
  init();
  for (int i = 0; i < (int)(n); i++) cin >> color[i];
  for (int i = 0; i < (int)(n - 1); i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 0; i < (int)(m); i++) {
    cin >> q[i].first >> q[i].second;
    q[i].first--;
    queries[q[i].first].push_back(i);
  }
  dfs(0, 0);
  for (int i = 0; i < (int)(m); i++) printf("%d\n", ans[i]);
  return 0;
}