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;
static struct IO {
  char tmp[1 << 10];
  char cur;
  inline char nextChar() { return cur = getc(stdin); }
  inline char peekChar() { return cur; }
  inline operator bool() { return peekChar(); }
  inline static bool isBlank(char c) { return (c < '-' && c); }
  inline bool skipBlanks() {
    while (isBlank(nextChar()))
      ;
    return peekChar() != 0;
  }
  inline IO& operator>>(char& c) {
    c = nextChar();
    return *this;
  }
  inline IO& operator>>(char* buf) {
    if (skipBlanks()) {
      if (peekChar()) {
        *(buf++) = peekChar();
        while (!isBlank(nextChar())) *(buf++) = peekChar();
      }
      *(buf++) = 0;
    }
    return *this;
  }
  inline IO& operator>>(string& s) {
    if (skipBlanks()) {
      s.clear();
      s += peekChar();
      while (!isBlank(nextChar())) s += peekChar();
    }
    return *this;
  }
  inline IO& operator>>(double& d) {
    if ((*this) >> tmp) sscanf(tmp, "%lf", &d);
    return *this;
  }
  inline IO& operator>>(int& n) {
    if (skipBlanks()) {
      int sign = +1;
      if (peekChar() == '-') {
        sign = -1;
        n = nextChar() - '0';
      } else
        n = peekChar() - '0';
      while (!isBlank(nextChar())) {
        n += n + (n << 3) + peekChar() - 48;
      }
      n *= sign;
    }
    return *this;
  }
  inline IO& operator>>(unsigned int& n) {
    if (skipBlanks()) {
      int sign = +1;
      if (peekChar() == '-') {
        sign = -1;
        n = nextChar() - '0';
      } else
        n = peekChar() - '0';
      while (!isBlank(nextChar())) {
        n += n + (n << 3) + peekChar() - 48;
      }
      n *= sign;
    }
    return *this;
  }
  inline IO& operator>>(long long& n) {
    if (skipBlanks()) {
      int sign = +1;
      if (peekChar() == '-') {
        sign = -1;
        n = nextChar() - '0';
      } else
        n = peekChar() - '0';
      while (!isBlank(nextChar())) {
        n += n + (n << 3) + peekChar() - 48;
      }
      n *= sign;
    }
    return *this;
  }
  inline void putChar(char c) { putc(c, stdout); }
  inline IO& operator<<(char c) {
    putChar(c);
    return *this;
  }
  inline IO& operator<<(const char* s) {
    while (*s) putChar(*s++);
    return *this;
  }
  inline IO& operator<<(const string& s) {
    for (int i = 0; i < (int)s.size(); ++i) putChar(s[i]);
    return *this;
  }
  char* toString(double d) {
    sprintf(tmp, "%lf%c", d, '\0');
    return tmp;
  }
  inline IO& operator<<(double d) { return (*this) << toString(d); }
  inline char* toString(int n) {
    char* p = (tmp + 30);
    if (n) {
      bool isNeg = 0;
      if (n < 0) isNeg = 1, n = -n;
      while (n) *--p = (n % 10) + '0', n /= 10;
      if (isNeg) *--p = '-';
    } else
      *--p = '0';
    return p;
  }
  inline IO& operator<<(int n) { return (*this) << toString(n); }
  inline char* toString(long long n) {
    char* p = (tmp + 30);
    if (n) {
      bool isNeg = 0;
      if (n < 0) isNeg = 1, n = -n;
      while (n) *--p = (n % 10) + '0', n /= 10;
      if (isNeg) *--p = '-';
    } else
      *--p = '0';
    return p;
  }
  inline IO& operator<<(long long n) { return (*this) << toString(n); }
} __io__;
const int MAXN = 100002;
const int BLOCK_SIZE = 317;
int c[MAXN];
vector<int> edges[MAXN];
int dfs_lo[MAXN];
int dfs_hi[MAXN];
bool vis[MAXN];
int cnt;
vector<pair<pair<int, int>, pair<int, int> > > block[BLOCK_SIZE];
int occur[MAXN];
int mark[MAXN];
int answers[MAXN];
int rev_map_dfs[MAXN];
bool my_cmp(const pair<pair<int, int>, pair<int, int> >& lhs,
            const pair<pair<int, int>, pair<int, int> >& rhs) {
  return lhs.first.first < rhs.first.first;
}
void dfs(int x) {
  vis[x] = true;
  dfs_lo[x] = ++cnt;
  rev_map_dfs[cnt] = x;
  for (int j = 0; j < (int)(edges[x].size()); j++) {
    int v = edges[x][j];
    if (vis[v]) continue;
    dfs(v);
  }
  dfs_hi[x] = cnt;
}
int main() {
  int n, m;
  __io__ >> n >> m;
  for (int i = 0; i < n; i++) __io__ >> c[i];
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    __io__ >> u >> v;
    --u, --v;
    edges[u].push_back(v);
    edges[v].push_back(u);
  }
  cnt = -1;
  dfs(0);
  for (int qq = 0; qq < m; qq++) {
    int v, k;
    __io__ >> v >> k;
    --v;
    int get_block = dfs_lo[v] / BLOCK_SIZE;
    block[get_block].push_back(
        make_pair(make_pair(dfs_hi[v], dfs_lo[v]), make_pair(k, qq)));
  }
  for (int i = 0; i < BLOCK_SIZE; i++) {
    sort(block[i].begin(), block[i].end(), my_cmp);
  }
  for (int i = 0; i < BLOCK_SIZE; i++) {
    if ((int)(block[i].size()) > 0) {
      memset(mark, 0, sizeof mark);
      memset(occur, 0, sizeof occur);
    }
    int L1 = -1, R1 = -1;
    for (int j = 0; j < (int)(block[i].size()); j++) {
      pair<pair<int, int>, pair<int, int> > query = block[i][j];
      int L = query.first.second, R = query.first.first, K = query.second.first;
      if (L1 == -1) {
        L1 = L;
        R1 = R;
        for (int z = L1; z <= R1; z++) {
          occur[c[rev_map_dfs[z]]]++;
          mark[occur[c[rev_map_dfs[z]]]]++;
        }
        answers[query.second.second] = mark[K];
      } else {
        if (L > L1) {
          for (int z = L1; z < L; z++) {
            if (occur[c[rev_map_dfs[z]]] > 0) {
              mark[occur[c[rev_map_dfs[z]]]]--;
            }
            occur[c[rev_map_dfs[z]]]--;
          }
        } else if (L < L1) {
          for (int z = L1 - 1; z >= L; z--) {
            occur[c[rev_map_dfs[z]]]++;
            mark[occur[c[rev_map_dfs[z]]]]++;
          }
        }
        L1 = L;
        for (int z = R1 + 1; z <= R; z++) {
          occur[c[rev_map_dfs[z]]]++;
          mark[occur[c[rev_map_dfs[z]]]]++;
        }
        R1 = R;
        answers[query.second.second] = mark[K];
      }
    }
  }
  for (int i = 0; i < m; i++) __io__ << answers[i] << '\n';
  return 0;
}