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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.File;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Atharva Nagarkar
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        JoltyScanner in = new JoltyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DTreeAndQueries solver = new DTreeAndQueries();
        solver.solve(1, in, out);
        out.close();
    }

    static class DTreeAndQueries {
        final int N = (int) 1e5 + 10;
        int n;
        int q;
        int[] size;
        int[] color;
        int[] qans;
        ArrayList<Integer>[] vs;
        ArrayList<Query>[] queries;
        int idx = 0;
        int[] first;
        int[] last;
        int[] cnt;
        int[] map;
        BIT bit;

        int dfs1(int node, int par) {
            int cur = 1;
            map[idx] = node;
            first[node] = idx++;
            for (int i : vs[node])
                if (i != par) {
                    cur += dfs1(i, node);
                }
            last[node] = idx;
            return size[node] = cur;
        }

        void add(int v) {
            int cur = cnt[color[v]];
            bit.add(cur, -1);
            cnt[color[v]] = ++cur;
            bit.add(cur, 1);
        }

        void remove(int v) {
            int cur = cnt[color[v]];
            bit.add(cur, -1);
            cnt[color[v]] = --cur;
            bit.add(cur, 1);
        }

        void dfs(int node, int par, boolean keep) {
            int maxChild = -1, maxSize = -1;
            for (int i : vs[node])
                if (i != par) {
                    if (size[i] > maxSize) {
                        maxChild = i;
                        maxSize = size[i];
                    }
                }
            for (int i : vs[node])
                if (i != par && i != maxChild) {
                    dfs(i, node, false);
                }
            if (maxChild != -1) {
                dfs(maxChild, node, true);
            }
            add(node);
            for (int i : vs[node])
                if (i != par && i != maxChild) {
                    for (int t = first[i]; t < last[i]; ++t) {
                        add(map[t]);
                    }
                }
            for (Query q : queries[node]) {
                int k = q.k;
                int i = q.id;
                qans[i] = (int) bit.sum(k, n + 1);
            }
            if (!keep) {
                for (int t = first[node]; t < last[node]; ++t) {
                    remove(map[t]);
                }
            }
        }

        public void solve(int testNumber, JoltyScanner in, PrintWriter out) {
            n = in.nextInt();
            q = in.nextInt();
            color = new int[N];
            cnt = new int[N];
            vs = new ArrayList[n];
            size = new int[n];
            qans = new int[q];
            queries = new ArrayList[n];
            bit = new BIT(n);
            map = new int[n];
            first = new int[n];
            last = new int[n];
            for (int i = 0; i < n; ++i) {
                vs[i] = new ArrayList<>();
                queries[i] = new ArrayList<>();
            }
            for (int i = 0; i < n; ++i) color[i] = in.nextInt() - 1;
            for (int i = 0; i < n - 1; ++i) {
                int u = in.nextInt() - 1;
                int v = in.nextInt() - 1;
                vs[u].add(v);
                vs[v].add(u);
            }
            for (int i = 0; i < q; ++i) {
                int v = in.nextInt() - 1;
                int k = in.nextInt();
                queries[v].add(new Query(i, v, k));
            }
            dfs1(0, -1);
            dfs(0, -1, true);
            for (int i : qans) out.println(i);
        }

        class Query {
            int v;
            int k;
            int id;

            Query(int a, int b, int c) {
                id = a;
                v = b;
                k = c;
            }

        }

    }

    static class JoltyScanner {
        public int BS = 1 << 16;
        public char NC = (char) 0;
        public byte[] buf = new byte[BS];
        public int bId = 0;
        public int size = 0;
        public char c = NC;
        public double num = 1;
        public BufferedInputStream in;

        public JoltyScanner(InputStream is) {
            in = new BufferedInputStream(is, BS);
        }

        public JoltyScanner(String s) throws FileNotFoundException {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
        }

        public char nextChar() {
            while (bId == size) {
                try {
                    size = in.read(buf);
                } catch (Exception e) {
                    return NC;
                }
                if (size == -1) return NC;
                bId = 0;
            }
            return (char) buf[bId++];
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public long nextLong() {
            num = 1;
            boolean neg = false;
            if (c == NC) c = nextChar();
            for (; (c < '0' || c > '9'); c = nextChar()) {
                if (c == '-') neg = true;
            }
            long res = 0;
            for (; c >= '0' && c <= '9'; c = nextChar()) {
                res = (res << 3) + (res << 1) + c - '0';
                num *= 10;
            }
            return neg ? -res : res;
        }

    }

    static class BIT {
        long[] tree;
        int n;

        public BIT(int nn) {
            n = nn + 10;
            tree = new long[n];
        }

        public void add(int i, long val) {
            i += 5;
            while (i <= n) {
                tree[i] += val;
                i += i & -i;
            }
        }

        public long sum(int to) {
            to += 5;
            long res = 0;
            for (int i = to; i >= 1; i -= (i & -i)) {
                res += tree[i];
            }
            return res;
        }

        public long sum(int from, int to) {
            if (from > to) return 0;
            return sum(to) - sum(from - 1);
        }

    }
}