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;
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> p) {
  out << '(' << p.first << ',' << p.second << ')';
  return out;
}
template <class T1, class T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
  in >> p.first >> p.second;
  return in;
}
template <class T>
istream& operator>>(istream& in, vector<T>& v) {
  for (auto& x : v) in >> x;
  return in;
}
template <class T>
ostream& operator<<(ostream& out, vector<vector<T>>& v) {
  for (auto& x : v) out << x << '\n';
  return out;
}
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
  for (auto x : v) out << x << ' ';
  return out;
}
const int N = 100005;
struct node {
  int ind, val, l, r;
} Q[N];
int a[N], A[N], bit[N], freq[N], color[N];
int n;
void update(int ind, int val) {
  for (int i = ind; i <= n; i += i & -i) {
    bit[i] += val;
  }
}
int query(int r) {
  int res = 0;
  while (r > 0) {
    res += bit[r];
    r -= r & -r;
  }
  return res;
}
inline void add(int i) {
  if (freq[color[a[i]]] > 0) {
    update(freq[color[a[i]]], -1);
  }
  freq[color[a[i]]]++;
  update(freq[color[a[i]]], 1);
}
inline void del(int i) {
  update(freq[color[a[i]]], -1);
  freq[color[a[i]]]--;
  if (freq[color[a[i]]] > 0) update(freq[color[a[i]]], 1);
}
vector<int> g[N];
int in[N], out[N], cur = 1;
bool vis[N];
void dfs(int second = 1) {
  vis[second] = true;
  a[cur] = second;
  in[second] = cur++;
  for (auto to : g[second]) {
    if (!vis[to]) dfs(to);
  }
  out[second] = cur - 1;
}
void Mo(int n, int q) {
  int BLOCK = max((int)(n / sqrt(q)), 1);
  sort(Q, Q + q, [&](node& a, node& b) {
    if (a.l / BLOCK == b.l / BLOCK) return a.r < b.r;
    return a.l / BLOCK < b.l / BLOCK;
  });
  int curL = 1, curR = 0;
  for (int i = 0; i < q; i++) {
    while (curR < Q[i].r) add(++curR);
    while (curR > Q[i].r) del(curR--);
    while (curL < Q[i].l) del(curL++);
    while (curL > Q[i].l) add(--curL);
    A[Q[i].ind] = query(n) - query(min(n, Q[i].val - 1));
  }
}
void solve() {
  int m;
  cin >> n >> m;
  for (int i = 1; i < n + 1; i++) {
    cin >> color[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs();
  for (int i = 0; i < m; i++) {
    int val;
    cin >> val >> Q[i].val;
    Q[i].ind = i;
    Q[i].l = in[val];
    Q[i].r = out[val];
  }
  Mo(n, m);
  for (int i = 0; i < m; i++) {
    cout << A[i] << "\n";
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cerr.tie(0);
  ;
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}