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.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class Solution {
    static class SegmentTree {
        private int n;
        private int[] a;

        SegmentTree() {
            n = 2;
            a = new int[2 * n];
        }

        void add(int position, int value) {
            if (position >= n) {
                int newSize = n;
                while(position >= newSize) {
                    newSize *= 2;
                }
                resize(newSize);
            }
            for (int i = position + n; i > 0; i /= 2) {
                a[i] += value;
            }
        }

        int sum(int lo) {
            int result = 0;
            for (int l = lo + n, r = 2 * n; l < r; l /= 2, r /= 2) {
                if (l % 2 == 1) {
                    result += a[l++];
                }
                if (r % 2 == 1) {
                    result += a[--r];
                }
            }
            return result;
        }

        private void resize(int newSize) {
            int[] b = new int[newSize * 2];
            System.arraycopy(a, n, b, newSize, n);
            for (int i = newSize - 1; i > 0; i--) {
                b[i] = b[2 * i] + b[2 * i + 1];
            }
            a = b;
            n = newSize;
        }
    }

    public static void main(String[] args) throws IOException {
        try (Input input = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) {
            int n = input.nextInt(), m = input.nextInt();
            int[] color = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                color[i] = input.nextInt();
            }
            @SuppressWarnings("unchecked")
            List<Integer>[] tree = new List[n + 1];
            for (int i = 1; i <= n; i++) {
                tree[i] = new ArrayList<>();
            }
            for (int i = 1; i < n; i++) {
                int u = input.nextInt(), v = input.nextInt();
                tree[u].add(v);
                tree[v].add(u);
            }
            @SuppressWarnings("unchecked")
            List<Integer>[] vertexQueries = new List[n + 1];
            for (int i = 1; i <= n; i++) {
                vertexQueries[i] = new ArrayList<>();
            }
            int[] queries = new int[m];
            for (int i = 0; i < m; i++) {
                vertexQueries[input.nextInt()].add(i);
                queries[i] = input.nextInt();
            }

            class DFS {
                private SegmentTree[] segmentTrees = new SegmentTree[n + 1];
                private int[] answer = new int[m];

                private Map<Integer, Integer> go(int u, int parent) {
                    int childrenCount = u == 1 ? tree[u].size() : tree[u].size() - 1;
                    if (childrenCount == 0) {
                        segmentTrees[u] = new SegmentTree();
                        segmentTrees[u].add(1, 1);
                        Map<Integer, Integer> map = new HashMap<>();
                        map.put(color[u], 1);
                        for (int qi : vertexQueries[u]) {
                            answer[qi] = segmentTrees[u].sum(queries[qi]);
                        }
                        return map;
                    }
                    @SuppressWarnings("unchecked")
                    Map<Integer, Integer>[] childrenMaps = new Map[childrenCount];
                    SegmentTree[] childrenSegmentTrees = new SegmentTree[childrenCount];
                    int ci = 0;
                    for (int v : tree[u]) {
                        if (v != parent) {
                            childrenMaps[ci] = go(v, u);
                            childrenSegmentTrees[ci++] = segmentTrees[v];
                        }
                    }
                    int biggestMapIndex = 0;
                    for (int i = 1; i < childrenCount; i++) {
                        if (childrenMaps[i].size() > childrenMaps[biggestMapIndex].size()) {
                            biggestMapIndex = i;
                        }
                    }
                    segmentTrees[u] = childrenSegmentTrees[biggestMapIndex];
                    Map<Integer, Integer> map = childrenMaps[biggestMapIndex];
                    if (map.containsKey(color[u])) {
                        int amount = map.get(color[u]);
                        segmentTrees[u].add(amount, -1);
                        amount++;
                        map.put(color[u], amount);
                        segmentTrees[u].add(amount, 1);
                    } else {
                        map.put(color[u], 1);
                        segmentTrees[u].add(1, 1);
                    }
                    for (int i = 0; i < childrenCount; i++) {
                        if (i != biggestMapIndex) {
                            for (Map.Entry<Integer, Integer> entry : childrenMaps[i].entrySet()) {
                                if (map.containsKey(entry.getKey())) {
                                    int amount = map.get(entry.getKey());
                                    segmentTrees[u].add(amount, -1);
                                    amount += entry.getValue();
                                    map.put(entry.getKey(), amount);
                                    segmentTrees[u].add(amount, 1);
                                } else {
                                    map.put(entry.getKey(), entry.getValue());
                                    segmentTrees[u].add(entry.getValue(), 1);
                                }
                            }
                        }
                    }
                    for (int qi : vertexQueries[u]) {
                        answer[qi] = segmentTrees[u].sum(queries[qi]);
                    }
                    return map;
                }
            }
            DFS dfs = new DFS();
            dfs.go(1, 0);
            for (int queryAnswer : dfs.answer) {
                writer.println(queryAnswer);
            }
        }
    }

    interface Input extends Closeable {
        String next() throws IOException;

        default int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        default long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }

    private static class StandardInput implements Input {
        private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        private StringTokenizer stringTokenizer;

        @Override
        public void close() throws IOException {
            reader.close();
        }

        @Override
        public String next() throws IOException {
            if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
                stringTokenizer = new StringTokenizer(reader.readLine());
            }
            return stringTokenizer.nextToken();
        }
    }
}