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.awt.*;
import java.io.*;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.Calendar.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;




public class Main{

    void run(){
        try {
            if( System.getProperty("ONLINE_JUDGE")!=null ){
                br = new BufferedReader( new InputStreamReader(System.in) );
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }
            else{
                br = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter(new FileWriter("output.txt"));
            }
        } catch (IOException e) {
            MLE();
        }
        solve();
        exit(0);
    }

    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    PrintWriter out;

    void exit(int val){
        out.flush();
        System.exit(val);
    }

    String next(){
        while( !st.hasMoreElements() )
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                return null;
            }
        return st.nextToken();
    }

    int nextInt(){ return Integer.parseInt(next()); }

    void MLE(){
        int[][] arr = new int[1024*1024][];
        for( int i = 0; i < arr.length; ++i )
            arr[i] = new int[1024*1024];
    }

    public static void main(String[] args){
        new Main().run();
    }
    ///////////////////////////////////////////////

    class Qw{
        int id, k;
        Qw( int _id, int _k ){
            id = _id;
            k  = _k;
        }
    }

    class Fen{
        int sumAll;
        int[] tree;
        Fen( int _n ){
            sumAll = 0;
            tree = new int[_n+1];
        }
        int sumSuf( int k ){
            return sumAll - sum( k-1 );
        }
        int sum( int pos ){
            pos = min( pos, tree.length - 1 );
            int ans = 0;
            for( int i = pos; 1 <= i;  i = (i&(i+1)) - 1 )
                ans += tree[i];
            return ans;
        }
        void inc( int pos, int delta ){
            sumAll += delta;
            for( int i = pos; i < tree.length; i = (i|(i+1)) )
                tree[i] += delta;
        }
    }

    int n, m;
    ArrayList<Integer>[] gr;
    ArrayList<Qw>[] qw;
    int[] c, cnt, toList, ans;

    void add( HashMap<Integer,Integer> b, int col, int cnt ){
        if( !b.containsKey(col) )
            b.put(col, cnt);
        else
            b.put( col, cnt + b.get(col) );
    }

    HashMap<Integer,Integer> fun( int v, int p, Fen fen ){
        int to0 = -1;
        HashMap<Integer,Integer>
                a = new HashMap<>(),
                b = new HashMap<>();
        for( int to : gr[v] ){
            if( to == p ) continue;
            if( to0 == -1 ){
                to0 = to;
                a = fun( to, v, fen );
            }
            else{
                for( Map.Entry<Integer,Integer> e : fun(to, v, new Fen(cnt[to] + 5)).entrySet() ){
                    int col = e.getKey();
                    int cnt = e.getValue();
                    add(b, col, cnt);
                }
            }
        }
        add( b, c[v], 1 );

        for( int col : b.keySet() ){
            int cnt = b.get(col);
            if( a.containsKey(col) ){
                fen.inc( a.get(col), -1 );
                fen.inc( a.get(col) + cnt, 1 );
            }
            else
                fen.inc( cnt, 1 );
            add( a, col, cnt );
        }

        for( Qw q : qw[v] ){
            ans[q.id] = fen.sumSuf( q.k );
        }

        return a;
    }

    void dfs( int v, int p ){
        toList[v] = 1;
        cnt[v] = 1;
        for( int to : gr[v] ){
            if( to == p ) continue;
            dfs( to, v );
            toList[v] = max( toList[v], toList[to] + 1 );
            cnt[v] += cnt[to];
        }
        Collections.sort(gr[v], new Comparator<Integer>() {
            public int compare(Integer a, Integer b) {
                //return -Integer.compare(toList[a], toList[b]);
                return -Integer.compare(cnt[a], cnt[b]);
            }
        });
    }

    void solve(){
        n = nextInt();
        m = nextInt();
        c = new int[n+1];
        for( int i = 1; i <= n; ++i )
            c[i] = nextInt();
        gr = new ArrayList[n+1];
        qw = new ArrayList[n+1];
        for( int i = 1; i <= n; ++i ){
            gr[i] = new ArrayList<>();
            qw[i] = new ArrayList<>();
        }
        for( int i = 0; i < n-1; ++i ){
            int a = nextInt();
            int b = nextInt();
            gr[a].add(b);
            gr[b].add(a);
        }
        for( int i = 0; i < m; ++i ){
            int v = nextInt();
            int k = nextInt();
            qw[v].add(new Qw(i,k));
        }

        toList = new int[n+1];
        cnt = new int[n+1];
        dfs(1,-1);

        ans = new int[m];
        fun( 1, -1, new Fen(cnt[1]+5) );
        for( int a : ans ) out.println( a );
    }

}