#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;
}
