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.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Random;
import java.util.SortedSet;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class TreeAndQueries {
    LinkedList<Integer>[] tree;
    LinkedList<int[]>[] queries;
    int[] qres;
    int[] color;
    Random r = new Random(System.nanoTime());
    class Node {
        long key;
        int priority;
        int size;
        Node[] next;
        public Node(long key) {
            this.key = key;
            priority = r.nextInt();
            size = 1;
            next = new Node[2];
        }
        public void refresh() {
            size = 1 + (next[0] != null ? next[0].size : 0)
                    + (next[1] != null ? next[1].size : 0);
        }
    }
    Node[] split(Node a, long key) {
        if (a == null)
            return new Node[] { null, null };
        int cmp = a.key < key ? 0 : 1;
        Node[] next = split(a.next[cmp ^ 1], key);
        a.next[cmp ^ 1] = next[cmp];
        next[cmp] = a;
        a.refresh();
        return next;
    }
    Node merge(Node a, Node b) {
        if (a == null || b == null)
            return b == null ? a : b;;
        if (a.priority < b.priority) {
            b.next[0] = merge(a, b.next[0]);
            b.refresh();
            return b;
        } else {
            a.next[1] = merge(a.next[1], b);
            a.refresh();
            return a;
        }
    }
    Node remove(Node t, long key) {
        if (t == null) 
            return null;
        if (key < t.key) {
            t.next[0] = remove(t.next[0], key);
            t.refresh();
            return t;
        } else if (key > t.key) {
            t.next[1] = remove(t.next[1], key);
            t.refresh();
            return t;
        } else
            return merge(t.next[0], t.next[1]);
    }
    Node insert(Node t, long key) {
        Node newNode = new Node(key);
        Node[] tsplit = split(t, key);
        return merge(merge(tsplit[0], newNode), tsplit[1]);
    }
    int csize(Node t, long key) {
        if (t == null)
            return 0;
        if (t.key < key)
            return csize(t.next[1], key);
        else
            return 1 + (t.next[1] != null ? t.next[1].size : 0)
                    + csize(t.next[0], key);
    }

    class SubtreeContents implements Comparable<SubtreeContents> {
        HashMap<Integer, Integer> M;
        Node S;
        int size;
        public SubtreeContents(int color) {
            M = new HashMap<>();
            S = new Node(1L << 32 | color);
            M.put(color, 1);
            size = 1;
        }
        public SubtreeContents merge(SubtreeContents s2) {
            long old_count;
            long key;
            size += s2.size;
            for (Entry<Integer, Integer> e : s2.M.entrySet()) {
                int color = e.getKey();
                int count = e.getValue();
                if (M.containsKey(color)) {
                    old_count = M.get(color);
                    key = old_count << 32 | color;
                    M.put(color, (int) (old_count + count));
                    S = remove(S, key);
                    S = insert(S, (old_count + count) << 32 | color);
                } else {
                    M.put(color, count);
                    S = insert(S, (count * 1L) << 32 | color);
                }
            }
            return this;
        }
        public int query(long bound) {
            return csize(S, bound << 32);
        }
        public int size() {
            return size;
        }
        @Override
        public int compareTo(SubtreeContents o) {
            return Integer.compare(size, o.size);
        }
    }
    public SubtreeContents dfs(int i, int p) {
        SubtreeContents c = new SubtreeContents(color[i]);
        for (int j : tree[i])
            if (j != p) {
                SubtreeContents tmp = dfs(j, i);
                if (tmp.size < c.size) {
                    c = c.merge(tmp);
                } else {
                    c = tmp.merge(c);
                }
            }
        for (int[] q : queries[i])
            qres[q[1]] = c.query(q[0]);
        return c;

    }

    public void run() throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer strtok = new StringTokenizer(in.readLine());
        int n = Integer.parseInt(strtok.nextToken());
        int q = Integer.parseInt(strtok.nextToken());
        tree = new LinkedList[n];
        queries = new LinkedList[n];
        qres = new int[q];
        color = new int[n];
        for (int i = 0; i < n; i++) {
            tree[i] = new LinkedList<>();
            queries[i] = new LinkedList<>();
        }
        strtok = new StringTokenizer(in.readLine());
        for (int i = 0; i < n; i++)
            color[i] = Integer.parseInt(strtok.nextToken());
        for (int i = 0; i < n - 1; i++) {
            strtok = new StringTokenizer(in.readLine());
            int a = Integer.parseInt(strtok.nextToken()) - 1;
            int b = Integer.parseInt(strtok.nextToken()) - 1;
            tree[a].add(b);
            tree[b].add(a);
        }
        for (int i = 0; i < q; i++) {
            strtok = new StringTokenizer(in.readLine());
            int v = Integer.parseInt(strtok.nextToken()) - 1;
            int k = Integer.parseInt(strtok.nextToken());
            queries[v].add(new int[] { k, i });
        }
        dfs(0, -1);
        StringBuilder out = new StringBuilder();
        for (int i = 0; i < q; i++)
            out.append(qres[i] + "\n");
        System.out.print(out);
    }

    public static void main(String[] args) throws Exception {
        (new TreeAndQueries()).run();
    }
}