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:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//package treeandqueries;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;

/**
 *
 * @author PrudhviRaj
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    static int n,m,in[],out[],t=0,c[],C[],ind=0;
    static ArrayList<Integer> tree[];
    
    static void dfs(int u){
        visited[u] = true;
        c[++ind] = C[u];
        in[u] = ++t;
        for(int x : tree[u]){
            if(!visited[x])
                dfs(x);
        }
        out[u] = t;
    }
    
    static boolean visited[];
    
    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        InputReader ir = new InputReader();
        n = ir.readInt();
        m = ir.readInt();
        C = ir.readIntArray1(n);
        c = new int[n+1];
        
        in = new int[n+1];
        out = new int[n+1];
        tree = new ArrayList[n+1];
        for(int i=0;i<=n;i++){
            tree[i] = new ArrayList();
        }
        for(int i=1;i<n;i++){
            int a = ir.readInt();
            int b = ir.readInt();
            tree[a].add(b);
            tree[b].add(a);
        }
        visited = new boolean[n+1];
        dfs(1);
//        System.out.println("In "+Arrays.toString(in));
//        System.out.println("Out "+Arrays.toString(out));
//        System.out.println("Col "+Arrays.toString(c));
        Q q[] = new Q[m];
        for(int i=0;i<m;i++){
            int u = ir.readInt();
            q[i] = new Q(i,in[u],out[u],ir.readInt());
        }
        final int buckets = (int)Math.sqrt(n);
        
        Arrays.sort(q, new Comparator<Q>(){
            @Override
            public int compare(Q o1, Q o2) {
                int b1 = o1.L/buckets;
                int b2 = o2.L/buckets;
                if(b1==b2){
                    return o1.R-o2.R;
                }
                return b1-b2;
            }    
            
        });
        //System.out.println(Arrays.toString(q));
        int MAX = 100001;
        int count[] = new int[MAX];
        int ccount[] = new int[MAX];
        int preL = q[0].L,preR = q[0].R;
        //System.out.println(q[0]);
//        for(int i=preL;i<=preR;i++){
//            count[c[i]]++;
//            ccount[count[c[i]]]++;
//        }
//        q[0].ans = ccount[q[0].k];
//        //System.out.println("Query "+q[0]);
//        System.out.println("Color "+Arrays.toString(count));
//        System.out.println("Freq "+Arrays.toString(ccount));
        preL = 1;
        preR = 1;
        count[c[1]]++;
        ccount[count[c[1]]]++;
        for(int i=0;i<m;i++){
            //System.out.println(q[i]);
            //System.out.println("Query "+q[i]);
            while(preL<q[i].L){
                //System.out.println("Left pointer Moving right");
                if(count[c[preL]]>0)
                    ccount[count[c[preL]]]--;
                
                
                count[c[preL]]--;
                preL++;
            }
            while(preL>q[i].L){
                //System.out.println("Left pointer moving left");
                preL--;
                count[c[preL]]++;
                
                if(count[c[preL]]>0)
                    ccount[count[c[preL]]]++;
            }
            while(preR<q[i].R){
                //System.out.println("Right pointer moving right");
                preR++;
                count[c[preR]]++;
                
                if(count[c[preR]]>0)
                    ccount[count[c[preR]]]++;
            }
            while(preR>q[i].R){
                //System.out.println("Right pointer moving left");
                if(count[c[preR]]>0)
                    ccount[count[c[preR]]]--;
                
                count[c[preR]]--;
                preR--;
            }
            
//            System.out.println("Color "+Arrays.toString(count));
//            System.out.println("freq "+Arrays.toString(ccount));
            q[i].ans = ccount[q[i].k];
        }
        int ans[] = new int[m];
        for(int i=0;i<m;i++){
            int ind = q[i].ind;
            int tans = q[i].ans;
            ans[ind] = tans;
        }
        for(int i=0;i<m;i++){
            System.out.println(ans[i]);
        }
        
    }
    
    static class Q{
        int ind,L,k,R;
        int ans=0;
        Q(int ind, int L, int R, int k){
            this.ind = ind;
            this.L = L;
            this.k = k;
            this.R = R;            
        }
        @Override
        public String toString(){
            return "{ind "+ind+" Left "+L+" Right "+R+" k "+k+"}";
        }
    }
    
    final static class InputReader {

        byte[] buffer = new byte[8192];
        int offset = 0;
        int bufferSize = 0;
        final InputStream in = System.in;

        public int readInt() throws IOException {
            int number = 0;
            int s = 1;
            if (offset == bufferSize) {
                offset = 0;
                bufferSize = in.read(buffer);
            }
            if (bufferSize == -1) {
                throw new IOException("No new bytes");
            }
            for (; buffer[offset] < 0x30 || buffer[offset] == '-'; ++offset) {
                if (buffer[offset] == '-') {
                    s = -1;
                }
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            for (; offset < bufferSize && buffer[offset] > 0x2f; ++offset) {
                number = (number << 3) + (number << 1) + buffer[offset] - 0x30;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            ++offset;
            return number * s;
        }

        public int[] readIntArray(int n) throws IOException {
            int[] ar = new int[n];
            for (int i = 0; i < n; i++) {
                ar[i] = readInt();
            }

            return ar;
        }

        public int[] readIntArray1(int n) throws IOException {
            int[] ar = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = readInt();
            }

            return ar;
        }

        public long readLong() throws IOException {
            long res = 0;
            int s = 1;
            if (offset == bufferSize) {
                offset = 0;
                bufferSize = in.read(buffer);
            }
            for (; buffer[offset] < 0x30 || buffer[offset] == '-'; ++offset) {
                if (buffer[offset] == '-') {
                    s = -1;
                }
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            for (; offset < bufferSize && buffer[offset] > 0x2f; ++offset) {
                res = (res << 3) + (res << 1) + buffer[offset] - 0x30;
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            ++offset;
            if (s == -1) {
                res = -res;
            }
            return res;
        }

        public long[] readLongArray(int n) throws IOException {
            long[] ar = new long[n];

            for (int i = 0; i < n; i++) {
                ar[i] = readLong();
            }

            return ar;
        }

        public String read() throws IOException {
            StringBuilder sb = new StringBuilder();
            if (offset == bufferSize) {
                offset = 0;
                bufferSize = in.read(buffer);
            }

            if (bufferSize == -1 || bufferSize == 0) {
                throw new IOException("No new bytes");
            }

            for (;
                    buffer[offset] == ' ' || buffer[offset] == '\t' || buffer[offset]
                    == '\n' || buffer[offset] == '\r'; ++offset) {
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            for (; offset < bufferSize; ++offset) {
                if (buffer[offset] == ' ' || buffer[offset] == '\t'
                        || buffer[offset] == '\n' || buffer[offset] == '\r') {
                    break;
                }
                if (Character.isValidCodePoint(buffer[offset])) {
                    sb.appendCodePoint(buffer[offset]);
                }
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            return sb.toString();
        }

        public String read(int n) throws IOException {
            StringBuilder sb = new StringBuilder(n);
            if (offset == bufferSize) {
                offset = 0;
                bufferSize = in.read(buffer);
            }

            if (bufferSize == -1 || bufferSize == 0) {
                throw new IOException("No new bytes");
            }

            for (;
                    buffer[offset] == ' ' || buffer[offset] == '\t' || buffer[offset]
                    == '\n' || buffer[offset] == '\r'; ++offset) {
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            for (int i = 0; offset < bufferSize && i < n; ++offset) {
                if (buffer[offset] == ' ' || buffer[offset] == '\t'
                        || buffer[offset] == '\n' || buffer[offset] == '\r') {
                    break;
                }
                if (Character.isValidCodePoint(buffer[offset])) {
                    sb.appendCodePoint(buffer[offset]);
                }
                if (offset == bufferSize - 1) {
                    offset = -1;
                    bufferSize = in.read(buffer);
                }
            }
            return sb.toString();
        }
    }
}