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;
const long long MOD = 1e9 + 7;
long long add(long long x, long long y, long long CMOD = MOD) {
  return (x + y + CMOD + CMOD) % CMOD;
}
long long mult(long long x, long long y, long long CMOD = MOD) {
  return add(x, 0) * add(y, 0) % CMOD;
}
long long fast_expo(long long x, long long y, long long CMOD = MOD) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  long long ans = fast_expo(x, y / 2, CMOD);
  ans = mult(ans, ans, CMOD);
  if (y & 1) ans = mult(ans, x, CMOD);
  return ans;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long gen(long long x, long long y) {
  if (x == y) return x;
  return x + rng() % (y - x + 1);
}
const int TAM = 1e5 + 100;
const long long INF = LLONG_MAX / 4;
int n, m;
int c[TAM];
vector<int> G[TAM];
vector<pair<int, int> > Q[TAM];
int ans[TAM];
int color[TAM];
int in[TAM];
int tam[TAM];
int timer = 0;
struct FT {
  vector<int> ft;
  int L;
  FT(int _L = 0) {
    L = _L + 1;
    ft.clear();
    ft.resize(L, 0);
  }
  int lsOne(int x) { return x & (-x); }
  void update(int pos, int dif) {
    for (int i = pos; i <= L; i += lsOne(i)) ft[i] += dif;
  }
  int Q(int pos) {
    int ans2 = 0;
    for (int i = pos; i > 0; i -= lsOne(i)) ans2 += ft[i];
    return ans2;
  }
  int query(int l, int r) {
    int ans2 = Q(r);
    if (l > 1) ans2 -= Q(l - 1);
    return ans2;
  }
};
void dfs_pre(int u, int pd) {
  color[timer] = c[u];
  in[u] = timer++;
  tam[u] = 1;
  for (int v : G[u]) {
    if (v != pd) {
      dfs_pre(v, u);
      tam[u] += tam[v];
    }
  }
}
FT ft;
int cont[TAM];
void add(int x) {
  if (cont[x] == 0) {
    cont[x]++;
    ft.update(1, 1);
  } else {
    ft.update(cont[x], -1);
    cont[x]++;
    ft.update(cont[x], 1);
  }
}
void remove(int x) {
  if (cont[x] == 1) {
    ft.update(1, -1);
    cont[x]--;
  } else {
    ft.update(cont[x], -1);
    cont[x]--;
    ft.update(cont[x], 1);
  }
}
void dfs(int u, int pd, bool keep) {
  int mx = -1, ix = -1;
  for (int v : G[u]) {
    if (v != pd and tam[v] > mx) {
      mx = tam[v];
      ix = v;
    }
  }
  for (int v : G[u]) {
    if (v != pd and v != ix) dfs(v, u, 0);
  }
  if (ix != -1) dfs(ix, u, 1);
  for (int v : G[u]) {
    if (v != pd and v != ix) {
      for (int i = in[v]; i < in[v] + tam[v]; i++) {
        int el = color[i];
        add(el);
      }
    }
  }
  add(color[in[u]]);
  for (auto xx : Q[u]) {
    int k = xx.first;
    int id = xx.second;
    ans[id] = ft.query(k, n);
  }
  if (keep == 0) {
    for (int i = in[u]; i < in[u] + tam[u]; i++) {
      int el = color[i];
      remove(el);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  ft = FT(TAM);
  for (int i = 0; i < n; i++) scanf("%d", &c[i]);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 0; i < m; i++) {
    int v, k;
    scanf("%d%d", &v, &k);
    v--;
    Q[v].push_back({k, i});
  }
  dfs_pre(0, -1);
  dfs(0, -1, 1);
  for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
  return 0;
}