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 Task3 {

    public static void main(String[] args) throws IOException {

        new Task3().solve();

    }

    //ArrayList<Integer>[] g;

    int mod = 1000000007;

    PrintWriter out;

    int n;
    int m;

    long inf = Long.MAX_VALUE;

    long base = (1L << 63);

    int[] a;
    int[] col;
    int[] sz;
    int[] p;

    ArrayList<Integer>[] g;

    int sqr;

    void solve() throws IOException {

        //Reader in = new Reader("m3.in");
        //out = new PrintWriter( new BufferedWriter(new FileWriter("m3.out")) );
        Reader in = new Reader();
        PrintWriter out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );

        //BufferedReader br = new BufferedReader( new FileReader("in.txt") );
        //BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );

        n = in.nextInt();
        m = in.nextInt();

        sqr = (int) Math.sqrt(n);

        col = new int[n];
        sz = new int[n];
        p = new int[n];
        a = new int[n];
        g = new ArrayList[n];

        for (int i = 0; i < n; i++) {

            col[i] = in.nextInt();
            g[i] = new ArrayList<>();
        }

        for (int i = 0; i < n-1; i++) {

            int x = in.nextInt()-1;
            int y = in.nextInt()-1;

            g[x].add(y);
            g[y].add(x);
        }

        sz[0] = dfs(0, -1);
        //bfs();

        Pair[] q = new Pair[m];

        for (int i = 0; i < m; i++) {

            int x = in.nextInt()-1;
            int y = in.nextInt();

            int l = p[x];
            int r = l + sz[x] - 1;

            q[i] = new Pair(l, r, y, i);
        }
//
//        for (int i = 0; i < n; i++)
//            out.print(a[i]+" ");

        Arrays.sort(q);

        int curL = 0;
        int curR = 0;

        for (int i = 0; i < m; i++) {

            int l = q[i].a;
            int r = q[i].b;
            int k = q[i].k;

            while (curR <= r) {
                add(curR);
                curR++;
            }

            while (curR > r+1) {
                del(curR-1);
                curR--;
            }

            while (curL < l) {
                del(curL);
                curL++;
            }

            while (curL > l) {

                add(curL-1);
                curL--;
            }

            //out.println(l+" "+r+" ");

            ans[q[i].i] = sf[k];
        }

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

        out.flush();
        out.close();
    }

    int[] ans = new int[100000];
    int[] cnt = new int[100010];
    int[] sf = new int[100010];

    void add(int pos) {

        int v = a[pos];

        cnt[col[v]]++;
        int k = cnt[col[v]];
        sf[k]++;
    }

    void del(int pos) {

        int v = a[pos];

        int k = cnt[col[v]];
        sf[k]--;
        cnt[col[v]]--;
    }

    void bfs() {

        boolean[] used = new boolean[n];
        Queue<Integer> q = new LinkedList<>();
        q.add(0);
        int pos = 0;
        used[0] = true;

        while (!q.isEmpty()) {

            int v = q.poll();

            a[pos] = v;
            p[v] = pos;
            pos++;

            for (int u : g[v])
                if (!used[u]) {
                    q.add(u);
                    used[u] = true;
                }
        }
    }

    int pos = 0;

    int dfs(int v, int pr) {

        a[pos] = v;
        p[v] = pos;
        pos++;

        int res = 1;

        for (int u : g[v])
            if (u != pr)
                res += dfs(u, v);

        sz[v] = res;

        return res;
    }

    long gcd(long a, long b) {

        if (b == 0)
            return a;

        return gcd(b, a%b);

    }

    class Pair implements Comparable<Pair>{

        int a;
        int b;
        int k;
        int i;

        Pair(int a, int b, int k, int i) {

            this.a = a;
            this.b = b;
            this.i = i;
            this.k = k;
        }

        public int compareTo(Pair p) {

            int b1 = a/sqr;
            int b2 = p.a/sqr;

            if (b1 > b2)
                return 1;

            if (b1 < b2)
                return -1;

            if (b > p.b)
                return 1;

            if (b < p.b)
                return -1;

            return 0;
        }

    }

    class Item {

        int a;
        int b;
        int c;

        Item(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }

    }

    class Reader {

        BufferedReader  br;
        StringTokenizer tok;

        Reader(String file) throws IOException {
            br = new BufferedReader( new FileReader(file) );
        }

        Reader() throws IOException {
            br = new BufferedReader( new InputStreamReader(System.in) );
        }

        String next() throws IOException {

            while (tok == null || !tok.hasMoreElements())
                tok = new StringTokenizer(br.readLine());
            return tok.nextToken();
        }

        int nextInt() throws NumberFormatException, IOException {
            return Integer.valueOf(next());
        }

        long nextLong() throws NumberFormatException, IOException {
            return Long.valueOf(next());
        }

        double nextDouble() throws NumberFormatException, IOException {
            return Double.valueOf(next());
        }

        String nextLine() throws IOException {
            return br.readLine();
        }

    }

}