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 JAVA):

Solution:
import java.io.*;
import java.util.*;

public class Main {

    private void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int m = in.nextInt();
        int[] colors = new int[n];
        for (int i = 0; i < n; i++) {
            colors[i] = in.nextInt();
        }

        List<Integer>[] tree = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            tree[i] = new ArrayList<>();
        }

        int a, b;
        for (int i = 0; i < n - 1; i++) {
            a = in.nextInt() - 1;
            b = in.nextInt() - 1;
            tree[a].add(b);
            tree[b].add(a);
        }

        Map<Integer, List<Query>> queries = new HashMap<>();
        int v, k;
        for (int i = 0; i < m; i++) {
            v = in.nextInt() - 1;
            k = in.nextInt();
            if (!queries.containsKey(v)) {
                queries.put(v, new ArrayList<>());
            }
            queries.get(v).add(new Query(k, i));
        }

        int[] size = new int[n];
        findSize(0, -1, tree, size);
        int[] ans = new int[m];
        int[] cnt = new int[100005];
        int[] above = new int[100005];
        dfs(0, -1, tree, size, ans, above, cnt, colors, queries);
        for (int i = 0; i < m; i++) {
            out.println(ans[i]);
        }
    }

    private void findSize(int v, int p, List<Integer>[] tree, int[] size) {
        size[v] = 1;
        for (int to: tree[v]) {
            if (to == p) continue;
            findSize(to, v, tree, size);
            size[v] += size[to];
        }
    }

    private void dfs(int v, int p, List<Integer>[] tree, int[] size, int[] ans, int[] above, int[] cnt, int[] colors, Map<Integer, List<Query>> queries) {
        int max = -1;
        for (int to: tree[v]) {
            if (to == p) continue;
            if (max < 0 || size[max] < size[to]) {
                max = to;
            }
        }

        for (int to: tree[v]) {
            if (to == p || to == max) continue;
            dfs(to, v, tree, size, ans, above, cnt, colors, queries);
            apply(to, v, tree, above, cnt, colors, true);
        }

        if (max >= 0) {
            dfs(max, v, tree, size, ans, above, cnt, colors, queries);
        }

        for (int to: tree[v]) {
            if (to == p || to == max) continue;
            apply(to, v, tree, above, cnt, colors, false);
         }
         cnt[colors[v]]++;
         above[cnt[colors[v]]]++;
         if (queries.containsKey(v)) {
             for (Query q: queries.get(v)) {
                 ans[q.idx] = above[q.k];
             }
         }
    }

    private void apply(int v, int p, List<Integer>[] tree, int[] above, int[] cnt, int[] colors, boolean rollback) {
        for (int to: tree[v]) {
            if (to == p) continue;
            apply(to, v, tree, above, cnt, colors, rollback);
        }

        if (rollback) {
            above[cnt[colors[v]]]--;
            cnt[colors[v]]--;
        } else {
            cnt[colors[v]]++;
            above[cnt[colors[v]]]++;
        }
    }

    static class Query {
        int k;
        int idx;

        public Query(int k, int idx) {
            this.k = k;
            this.idx = idx;
        }
    }

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        new Main().solve(in, out);
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}