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>
template <class T>
struct fenwick_tree_t {
  std::vector<T> A;
  fenwick_tree_t(size_t N) : A(N) {}
  void add(const size_t p, T v) {
    for (size_t i = p + 1; i > 0 && i <= A.size(); i += i & -i) {
      A[i - 1] += v;
    }
  }
  T sum(const size_t r) const {
    T s{};
    for (size_t i = r + 1; i > 0 && i <= A.size(); i -= i & -i) {
      s += A[i - 1];
    }
    return s;
  }
  T sum(size_t l, size_t r) const { return sum(r) - sum(l - 1); }
  T rsum(size_t l) const { return sum(l, A.size() - 1); }
};
struct range_t {
  size_t l, r, i, q;
};
class mo_t {
  static std::vector<int> remap(std::vector<int> &vector) {
    std::map<int, size_t> map;
    for (size_t i = 0; i < vector.size(); i++) {
      map.insert({vector[i], 0});
    }
    std::vector<int> reverse(map.size());
    size_t i = 0;
    for (auto &it : map) {
      it.second = i;
      reverse[i] = it.first;
      i++;
    }
    for (size_t i = 0; i < vector.size(); i++) {
      vector[i] = map[vector[i]];
    }
    return reverse;
  }
  static std::vector<range_t> &init_ranges(std::vector<range_t> &ranges,
                                           const size_t sqrt) {
    std::sort(ranges.begin(), ranges.end(),
              [sqrt](const range_t &lhs, const range_t &rhs) {
                const size_t L = lhs.l / sqrt;
                const size_t R = rhs.l / sqrt;
                if (L != R) return L < R;
                return lhs.r < rhs.r;
              });
    return ranges;
  }

 public:
  mo_t(std::vector<int> &data, std::vector<range_t> &pairs)
      : data(data),
        reverse(remap(data)),
        ranges(init_ranges(pairs, std::sqrt(data.size()))),
        answer(1 + data.size()),
        answers(ranges.size()),
        counters(reverse.size()) {}
  const std::vector<int> &operator()() {
    size_t curr_i = 0;
    size_t curr_j = 0;
    for (const range_t &range : ranges) {
      size_t i = range.l;
      size_t j = range.r;
      while (curr_i < i) {
        del(curr_i);
        curr_i++;
      }
      while (curr_i > i) {
        curr_i--;
        add(curr_i);
      }
      while (curr_j < j + 1) {
        add(curr_j);
        curr_j++;
      }
      while (curr_j > j + 1) {
        curr_j--;
        del(curr_j);
      }
      answers[range.i] = answer.rsum(range.q);
    }
    return answers;
  }

 protected:
  virtual void add(size_t k) = 0;
  virtual void del(size_t k) = 0;
  std::vector<int> &data;
  const std::vector<int> reverse;
  const std::vector<range_t> ranges;
  fenwick_tree_t<int> answer;
  std::vector<int> answers;
  std::vector<int> counters;
};
struct tree_t {
  int value;
  size_t origin;
  std::vector<std::reference_wrapper<tree_t>> linked;
  static void flatten(std::vector<int> &data, std::vector<range_t> &ranges,
                      const std::vector<std::pair<size_t, size_t>> &edges) {
    std::vector<tree_t> vertices;
    vertices.reserve(data.size());
    for (size_t i = 0; i < data.size(); ++i) {
      vertices.push_back({data[i], i});
    }
    for (size_t i = 0; i < edges.size(); ++i) {
      vertices[edges[i].first].linked.push_back(vertices[edges[i].second]);
      vertices[edges[i].second].linked.push_back(vertices[edges[i].first]);
    }
    std::vector<bool> visited(data.size(), false);
    std::vector<size_t> begins(data.size());
    std::vector<size_t> ends(data.size());
    std::function<void(tree_t & v, int64_t & i)> preorder;
    preorder = [&](tree_t &v, int64_t &i) {
      if (visited[v.origin]) {
        return;
      }
      visited[v.origin] = true;
      i++;
      begins[v.origin] = i;
      data[i] = v.value;
      std::vector<int> result{v.value};
      for (tree_t &child : v.linked) {
        preorder(child, i);
      }
      ends[v.origin] = i;
    };
    int64_t i = -1;
    preorder(vertices[0], i);
    for (auto &range : ranges) {
      size_t o = range.l;
      range.l = begins[o];
      range.r = ends[o];
    }
  }
};
void solve(std::vector<int> &data, std::vector<range_t> &ranges,
           const std::vector<std::pair<size_t, size_t>> &edges) {
  tree_t::flatten(data, ranges, edges);
  struct _ : public mo_t {
    void add(size_t k) {
      answer.add(counters[data[k]], -1);
      counters[data[k]]++;
      answer.add(counters[data[k]], +1);
    }
    void del(size_t k) {
      answer.add(counters[data[k]], -1);
      counters[data[k]]--;
      answer.add(counters[data[k]], +1);
    }
    _(std::vector<int> &data, std::vector<range_t> &ranges)
        : mo_t(data, ranges) {}
  } mo(data, ranges);
  for (int answer : mo()) {
    printf("%d\n", answer);
  }
}
int main() {
  int N;
  scanf("%d", &N);
  int M;
  scanf("%d", &M);
  std::vector<int> data;
  data.reserve(N);
  std::vector<std::pair<size_t, size_t>> edges;
  edges.reserve(N - 1);
  std::vector<range_t> ranges;
  ranges.reserve(M);
  for (int i = 0; i < N; i++) {
    int value;
    scanf("%d", &value);
    data.push_back(value);
  }
  for (int i = 1; i < N; i++) {
    std::pair<size_t, size_t> edge;
    scanf("%lu%lu", &edge.first, &edge.second);
    edge.first--;
    edge.second--;
    edges.push_back(edge);
  }
  for (int i = 0; i < M; i++) {
    range_t range;
    scanf("%lu%lu", &range.l, &range.q);
    range.l--;
    range.i = i;
    ranges.push_back(range);
  }
  solve(data, ranges, edges);
  return 0;
}