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.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.InputStream;

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

class TaskD {
    int[] color;
    int[] temp;
    int[] lc;
    int[] rc;

    int cnt = 0;
    int[] head;
    int[] next;
    int[] end;

    int stamp = 0;
    final int SIZE = 330;

    class Query implements Comparable<Query> {
        int l;
        int r;
        int k;
        int block;
        int index;

        Query(int l, int r, int block, int index, int k) {
            this.l = l;
            this.r = r;
            this.index = index;
            this.block = block;
            this.k = k;
        }

        public int compareTo(Query o) {
            Integer thisBlock = new Integer(this.block);
            Integer oBlock = new Integer(o.block);
            Integer thisR = new Integer(this.r);
            Integer oR = new Integer(o.r);
            if (thisBlock - oBlock == 0)
                return thisR.compareTo(oR);
            return thisBlock.compareTo(oBlock);
        }
    }

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int nq = in.nextInt();
        Query[] query = new Query[nq + 1];
        color = new int[n + 1];
        temp = new int[n + 1];
        lc = new int[n + 1];
        rc = new int[n + 1];

        head = new int[n + 1];
        next = new int[n * 2 + 5];
        end = new int[n * 2 + 5];

        for (int i = 1; i <= n; i++) {
            temp[i] = in.nextInt();
            head[i] = -1;
        }

        for (int i = 1; i <= n - 1; i++) {
            int from = in.nextInt();
            int to = in.nextInt();
            addEdge(from, to);
            addEdge(to, from);
        }
        dfs(1, -1);
        for (int i = 1; i <= nq; i++) {
            int u = in.nextInt();
            int k = in.nextInt();
            query[i] = new Query(lc[u], rc[u], lc[u] / SIZE, i, k);
        }
        Arrays.sort(query, 1, nq);
        int[] answer = new int[nq + 1];
        int[] occur = new int[n + 1];
        int[] total = new int[100005];
        int L = query[1].l;
        int R = query[1].r;
        for (int i = L; i <= R; i++) {
            occur[++total[color[i]]]++;
        }
        answer[query[1].index] = query[1].k > n ? 0 : occur[query[1].k];
        for (int i = 2; i <= nq; i++) {
            int ql = query[i].l;
            int qr = query[i].r;
            while (R < qr) {
                R++;
                occur[++total[color[R]]]++;
            }
            while (L > ql) {
                L--;
                occur[++total[color[L]]]++;
            }
            while (R > qr) {
                occur[total[color[R]]--]--;
                R--;
            }
            while (L < ql) {
                occur[total[color[L]]--]--;
                L++;
            }
            answer[query[i].index] = query[i].k > n ? 0 : occur[query[i].k];
        }
        for (int i = 1; i <= nq; i++)
            out.println(answer[i]);
    }

    public void dfs(int u, int father) {
        lc[u] = ++stamp;
        color[stamp] = temp[u];
        for (int i = head[u]; i != -1; i = next[i]) {
            if (end[i] == father)
                continue;
            dfs(end[i], u);
        }
        rc[u] = stamp;
    }

    public void addEdge(int from, int to) {
        end[cnt] = to;
        next[cnt] = head[from];
        head[from] = cnt++;
    }
}

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());
    }
}