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.IOException;
import java.io.InputStream;
import java.util.*;


public class Solution {
    static int n,MN;
    static ArrayList<Integer>[] tree;
    static int start[],end[],euler[],color[],freq[],prefix[];
    static int count;
    static void dfs(int u,int p){
        start[u]=count;
        euler[count]=u;
        count++;
        for(int v:tree[u]){
            if(v!=p){
                dfs(v,u);
            }
        }
        end[u]=count-1;
    }

    static void add(int z){
        if(z<0 || z>MN)
            return;
        int x=color[euler[z]];
        freq[x]++;
        prefix[freq[x]]++;
    }

    static void remove(int z){
        if(z<0 || z>MN)
            return;
        int x=color[euler[z]];
        prefix[freq[x]]--;
        freq[x]--;
    }

    public static void main(String args[]) throws IOException {
        FastReader in = new FastReader(System.in);
        StringBuilder sb=new StringBuilder();
        int i, j;
        MN=100000;
        n=in.nextInt();
        int q=in.nextInt();
        tree=new ArrayList[n];
        start=new int[n];
        end=new int[n];
        euler=new int[n];
        color=new int[n];
        freq=new int[MN+1];
        prefix=new int[MN+1];
        int ans[]=new int[q];
        count=0;
        for(i=0;i<n;i++) {
            tree[i] = new ArrayList<>();
            color[i]=in.nextInt();
        }
        for(i=0;i<n-1;i++){
            int x=in.nextInt()-1;
            int y=in.nextInt()-1;
            tree[x].add(y);
            tree[y].add(x);
        }

        dfs(0,-1);

        int query[][]=new int[q][3];
        for(i=0;i<q;i++){
            int x=in.nextInt()-1;
            query[i][0]=start[x];
            query[i][1]=end[x];
            query[i][2]=in.nextInt();
        }

        Integer ind[]=new Integer[q];
        for(i=0;i<q;i++)
            ind[i]=i;

        int size=600;

        Arrays.sort(ind, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                int b1=query[o1][0]/size;
                int b2=query[o2][0]/size;
                if(b1!=b2){
                    return Integer.compare(b1,b2);
                }

                if(b1%2==0)
                    return Integer.compare(query[o1][1],query[o2][1]);
                return -Integer.compare(query[o1][1],query[o2][1]);

            }
        });

        int L=-1,R=-1;
        for(i=0;i<q;i++){
            int id=ind[i];
            int l=query[id][0];
            int r=query[id][1];

            while(R<r){
                add(++R);
            }
            while(l<L){
                add(--L);
            }

            while(l>L){
                remove(L++);
            }

            while(R>r){
                remove(R--);
            }



            ans[id]=prefix[query[id][2]];
        }

        for(i=0;i<q;i++)
            sb.append(ans[i]).append("\n");

        System.out.print(sb);

    }
}

class FastReader {

    byte[] buf = new byte[2048];
    int index, total;
    InputStream in;

    FastReader(InputStream is) {
        in = is;
    }

    int scan() throws IOException {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0) {
                return -1;
            }
        }
        return buf[index++];
    }

    String next() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }

    int nextInt() throws IOException {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }

    long nextLong() throws IOException {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }
}