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.text.DecimalFormat;
import java.util.*;
import java.awt.Point;
import java.math.BigInteger;

public class Newbie {

    static InputReader sc = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        solver s = new solver();
        int t = 1;
        while (t > 0) {
            s.solve();
            t--;
        }
        out.close();
    }

    static class InputReader {

        public BufferedReader br;
        public StringTokenizer token;

        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream), 32768);
            token = null;
        }

        public String sn() {
            while (token == null || !token.hasMoreTokens()) {
                try {
                    token = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return token.nextToken();
        }

        public int ni() {
            return Integer.parseInt(sn());
        }

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

        public long nlo() {
            return Long.parseLong(sn());
        }

        public double nd() {
            return Double.parseDouble(sn());
        }

        public int[] na(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = sc.ni();
            return a;
        }

        public long[] nal(int n) {
            long a[] = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = sc.nlo();
            return a;
        }
    }

    static class extra {

        static long fastexpo(long x, long y) {
            long res = 1;
            while (y > 0) {
                if ((y & 1) == 1) {
                    res *= x;
                }
                y = y >> 1;
                x = x * x;
            }
            return res;
        }

        static long lfastexpo(long x, long y, long p) {
            long res = 1;
            x = x % p;
            while (y > 0) {
                if ((y & 1) == 1) {
                    res = (res * x) % p;
                }
                y = y >> 1;
                x = (x * x) % p;
            }
            return res;
        }
    }

    static int inf = 5000013;

    static class solver {
        DecimalFormat df = new DecimalFormat("0.00000000");
        extra e = new extra();
        long mod = (long) (1e9 + 7);
        List<Integer> list[];
        int c[], st[], size[], arr[], time, block, n;
        boolean v[];

        class q implements Comparable<q> {
            int l, r, i, k;

            q(int a, int b, int c, int d) {
                l = a;
                r = b;
                i = c;
                k = d;
            }

            public int compareTo(q x) {
                if ((this.l / block) != (x.l / block))
                    return this.l - x.l;
                return ((this.l / block) % 2 == 0) ? (x.r - this.r) : (this.r - x.r);
            }
        }

        void dfs(int s) {
            v[s] = true;
            st[s] = time++;
            size[s] = 1;
            for (int adj : list[s]) {
                if (!v[adj]) {
                    dfs(adj);
                    size[s] += size[adj];
                }
            }
        }

        int f[] = new int[100005];
        int ff[] = new int[100005];

        void solve() {
            n = sc.ni();
            v = new boolean[n];
            st = new int[n];
            size = new int[n];
            arr = new int[n];
            int m = sc.ni();
            c = sc.na(n);
            list = new ArrayList[n];
            for (int i = 0; i < n; i++) {
                list[i] = new ArrayList<>();
            }
            for (int i = 0; i < n - 1; i++) {
                int u = sc.ni() - 1;
                int v = sc.ni() - 1;
                list[u].add(v);
                list[v].add(u);
            }
            dfs(0);
            block = (int) Math.ceil(Math.sqrt(n));
            for (int i = 0; i < n; i++)
                arr[st[i]] = c[i];
//            System.out.println(Arrays.toString(arr));
            q b[] = new q[m];
            for (int i = 0; i < m; i++) {
                int u = sc.ni() - 1;
                int l = st[u];
                int r = st[u] + size[u] - 1;
                int k = sc.ni();
                b[i] = new q(l, r, i, k);
            }
            Arrays.sort(b);
            int cl = 0;
            int cr = -1;
            int ans[] = new int[m];
            for (int i = 0; i < m; i++) {
                int l = b[i].l;
                int r = b[i].r;
                int k = b[i].k;
//                System.out.println(l + " " + r + " " + k);
                while (cl < l) {
                    remove(arr[cl]);
                    cl++;
                }
                while (cl > l) {
                    cl--;
                    add(arr[cl]);
                }
                while (cr < r) {
                    cr++;
                    add(arr[cr]);
                }
                while (cr > r) {
                    remove(arr[cr]);
                    cr--;
                }
                ans[b[i].i] = ff[k];
            }
            for (int h : ans)
                out.println(h);
        }

        void add(int a) {
            f[a]++;
            if (f[a] >= 0)
                ff[f[a]]++;
        }

        void remove(int a) {
//            System.out.println(a);
            if (f[a] >= 0)
                ff[f[a]]--;
            f[a]--;
        }
    }
}