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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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 {
    private final int oo = (int) (2e5 + 5);
    private final int inc = (int) 1e5;
    private final int hs = 500;

    private class Query implements Comparable<Query> {
        int l, r, k, id;

        public Query(int l, int r, int k, int id) {
            this.l = l;
            this.r = r;
            this.k = k;
            this.id = id;
        }

        public int compareTo(Query o) {
            return (l / hs != o.l / hs ? l / hs - o.l / hs : (r != o.r ? r - o.r : (k != o.k ? k - o.k : id - o.id)));
        }
    }

    private int n, m, time;
    private ArrayList<Integer>[] head;
    private int[] start, end, tmp_a, a, res, sum, cnt;
    private Query[] q;

    private void Init() {
        head = new ArrayList[n + 1];
        tmp_a = new int[n + 1];
        a = new int[n + 1];
        start = new int[n + 1];
        end = new int[n + 1];
        for (int i = 1; i <= n; ++i) head[i] = new ArrayList<>();
    }

    private void DFS(int u, int pre) {
        ++time;
        start[u] = time;
        for (int v : head[u])
            if (pre != v) DFS(v, u);
        end[u] = time;
    }

    private void Add(int i) {
        ++sum[cnt[a[i]] + 1 + inc];
        ++cnt[a[i]];
    }

    private void Sub(int i) {
        --sum[cnt[a[i]] + inc];
        --cnt[a[i]];
    }

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        n = in.nextInt();
        m = in.nextInt();

        Init();

        for (int i = 1; i <= n; ++i) tmp_a[i] = in.nextInt();
        for (int i = 1; i < n; ++i) {
            int x = in.nextInt(), y = in.nextInt();
            head[x].add(y);
            head[y].add(x);
        }

        DFS(1, 0);
        for (int i = 1; i <= n; ++i)
            a[start[i]] = tmp_a[i];

        q = new Query[m];
        for (int i = 0; i < m; ++i) {
            int u = in.nextInt(), k = in.nextInt();
            q[i] = new Query(start[u], end[u], k, i);
        }

        Arrays.sort(q);

        res = new int[m];
        sum = new int[oo];
        cnt = new int[oo];
        int cur_l = 0, cur_r = 0;
        for(int i = 0; i < m; ++i) {
            int l = q[i].l, r = q[i].r, k = q[i].k, id = q[i].id;

            while (cur_l < l) {
                Sub(cur_l); ++cur_l;
            }
            while (cur_l > l) {
                Add(cur_l - 1); --cur_l;
            }
            while (cur_r <= r) {
                Add(cur_r); ++cur_r;
            }
            while (cur_r > r + 1) {
                Sub(cur_r - 1); --cur_r;
            }

            res[id] = sum[k + inc];
        }

        for(int i = 0; i < m; ++i) out.println(res[i]);
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

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

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

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

}