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.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class TreeAndQueries {
    
    private static class Node {
        public List<Integer> children = new ArrayList<Integer>();
        public boolean flag = true;
    }
    
    private static class Query {
        public int p, k, l, r, ans;
    }
    
    private Node[] tree;
    
    private int n, m, maxColor, totalColor;
    
    private int color[];
    
    private Query queries[];
    
    private Integer p[];

    private void input() throws Exception {
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in));
        String str = reader.readLine();
        String[] ss = str.split(" ");
        n = Integer.valueOf(ss[0]);
        m = Integer.valueOf(ss[1]);
        color = new int[n];
        Set<Integer> colorSet = new HashSet<Integer>();
        maxColor = 0;
        str = reader.readLine();
        ss = str.split(" ");
        for (int i = 0; i < n; i++) {
            color[i] = Integer.valueOf(ss[i]);
            maxColor = Math.max(color[i], maxColor);
            colorSet.add(color[i]);
        }
        totalColor = colorSet.size();
        tree = new Node[n];
        for (int i = 0; i < n; i++) tree[i] = new Node();
        for (int i = 0; i < n - 1; i++) {
            str = reader.readLine();
            ss = str.split(" ");
            int s = Integer.valueOf(ss[0]) - 1;
            int t = Integer.valueOf(ss[1]) - 1;
            tree[s].children.add(t);
            tree[t].children.add(s);
        }
        queries = new Query[m];
        p = new Integer[m];
        for (int i = 0; i < m; i++) {
            p[i] = i;
            str = reader.readLine();
            ss = str.split(" ");
            queries[i] = new Query();
            queries[i].p = Integer.valueOf(ss[0]) - 1;
            queries[i].k = Integer.valueOf(ss[1]);
        }
    }
    
    private int lp[], rp[], w[], cnt;
    
    private void dfs(int p) {
        Node node = tree[p];
        if (node.flag) {
            node.flag = false;
            w[cnt] = p;
            lp[p] = cnt++;
            for (int child : node.children) {
                dfs(child);
            }
            w[cnt] = -1;
            rp[p] = cnt++;
        }
    }
    
    private int c[], colorCnt[];
    
    private int lowbit(int p) {
        return p & (p ^ (p - 1));
    }
    
    private void modify(int p, int delta) {
        p++;
        while (p <= n+1) {
            c[p] += delta;
            p += lowbit(p);
        }
    }
    
    private int get(int p) {
        p++;
        int s = 0;
        while (p > 0) {
            s += c[p];
            p -= lowbit(p);
        }
        return s;
    }
    
    private void solve() {
        lp = new int[n*2];
        rp = new int[n*2];
        w = new int[n*2];
        cnt = 0;
        dfs(0);
        for (int i = 0; i < m; i++) {
            queries[i].l = lp[queries[i].p];
            queries[i].r = rp[queries[i].p];
        }
        Arrays.sort(p, new Comparator<Integer>() {
            public int compare(Integer x, Integer y) {
                Query q1 = queries[x];
                Query q2 = queries[y];                
                return (q1.l/3000 == q2.l/3000)? q1.r - q2.r : q1.l - q2.l;
            }
        });
        int l = -1;
        int r = -1;
        c = new int[n + 2];
        colorCnt = new int[maxColor + 1];
        modify(0, totalColor);
        for (int i = 0; i < m; i++) {
            Query q = queries[p[i]];
            if (q.k > n) {
                q.ans = 0;
                continue;
            }
            while (l > q.l) {
                l--;
                int p = w[l];
                if (p >= 0) {
                    modify(colorCnt[color[p]], -1);
                    colorCnt[color[p]]++;
                    modify(colorCnt[color[p]], 1);
                }
            }
            while (r < q.r) {
                r++;
                int p = w[r];
                if (p >= 0) {
                    modify(colorCnt[color[p]], -1);
                    colorCnt[color[p]]++;
                    modify(colorCnt[color[p]], 1);
                }
            }
            while (l < q.l) {
                if (l >= 0) {
                    int p = w[l];
                    if (w[l] >= 0) {
                        modify(colorCnt[color[p]], -1);
                        colorCnt[color[p]]--;
                        modify(colorCnt[color[p]], 1);
                    }
                }
                l++;
            }
            while (r > q.r) {
                int p = w[r];
                if (p >= 0) {
                    modify(colorCnt[color[p]], -1);
                    colorCnt[color[p]]--;
                    modify(colorCnt[color[p]], 1);
                }
                r--;
            }
            q.ans = totalColor - get(q.k - 1);
        }
    }
    
    private void output() {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < m; i++) {
            result.append(queries[i].ans).append('\n');
        }
        System.out.println(result);
    }
    
    public static void main(String[] args) throws Exception {
        TreeAndQueries instance = new TreeAndQueries();
        instance.input();
        instance.solve();
        instance.output();
    }
    
}