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 GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
using namespace std;
long double eps = (long double)1 / 1e6;
int inf = 1e18, mod2 = 998244353, mod1 = 1e9 + 7;
int sqr(int a) { return a * a; }
int qb(int a) { return a * a * a; }
int gcd(int a, int b) { return !a ? b : gcd(b % a, a); }
int binpow(int a, int b, int mod) {
  return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod
                    : sqr(binpow(a, b / 2, mod)) % mod)
           : 1;
}
int binmult(int a, int b, int mod) {
  return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod
                    : (2 * binmult(a, b / 2, mod)) % mod)
           : 0;
}
const int R = 1e4;
const int tx[4] = {0, 0, -1, 1};
const int ty[4] = {-1, 1, 0, 0};
const char rev_to[4] = {'E', 'W', 'N', 'S'};
const int N = 4 * 1e5 + 1;
const int block = 347;
vector<int> g[N];
int cnt = 0;
int a[N];
int in[N], out[N];
int b[N];
void dfs(int v, int p) {
  in[v] = cnt;
  cnt++;
  for (auto u : g[v]) {
    if (u != p) {
      dfs(u, v);
    }
  }
  out[v] = cnt - 1;
}
struct triple {
  int a, b, c, d;
};
int who = 0;
bool cmp(triple a, triple b) {
  if (a.a / block != b.a / block) {
    return a.a / block < b.a / block;
  }
  return a.b < b.b;
}
int fnw[N];
int cntffnw[N];
void add(int indx, int val) {
  if (indx <= 0) return;
  who += val;
  while (indx < N) {
    fnw[indx] += val;
    indx += indx & (-indx);
  }
}
int get(int k) {
  if (!k) return 0;
  int ans = 0;
  while (k >= 1) {
    ans += fnw[k];
    k -= k & (-k);
  }
  return ans;
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  int v, u;
  for (int i = 1; i < n; i++) {
    cin >> v >> u;
    --u;
    v--;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  dfs(0, -1);
  for (int i = 0; i < n; i++) {
    b[in[i]] = a[i];
  }
  int l, r;
  vector<triple> querys(m);
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    --l;
    querys[i] = {in[l], out[l], r, i};
  }
  vector<int> ans(m);
  sort(querys.begin(), querys.end(), cmp);
  int curl = 0, curr = 0, pos = -1;
  cntffnw[b[curl]]++;
  int val;
  add(cntffnw[b[curl]], 1);
  for (int i = 0; i < m; i++) {
    l = querys[i].a, r = querys[i].b, val = querys[i].c, pos = querys[i].d;
    while (curl < l) {
      add(cntffnw[b[curl]], -1);
      cntffnw[b[curl]]--;
      add(cntffnw[b[curl]], 1);
      curl++;
    }
    while (curl > l) {
      add(cntffnw[b[curl - 1]], -1);
      cntffnw[b[curl - 1]]++;
      add(cntffnw[b[curl - 1]], 1);
      curl--;
    }
    while (curr > r) {
      add(cntffnw[b[curr]], -1);
      cntffnw[b[curr]]--;
      add(cntffnw[b[curr]], 1);
      curr--;
    }
    while (curr < r) {
      add(cntffnw[b[curr + 1]], -1);
      cntffnw[b[curr + 1]]++;
      add(cntffnw[b[curr + 1]], 1);
      curr++;
    }
    ans[pos] = who - get(val - 1);
  }
  for (auto z : ans) {
    cout << z << "\n";
  }
  return 0;
}