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:
	/*	/ ﾌﾌ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ム
		/ )\⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀  Y
		(⠀⠀| ( ͡° ͜ʖ ͡°）⠀⌒(⠀ ノ
		(⠀ ﾉ⌒ Y ⌒ヽ-く __／
		| _⠀｡ノ| ノ｡ |/
		(⠀ー '_人`ー ﾉ
		⠀|\ ￣ _人'彡ﾉ
		⠀ )\⠀⠀ ｡⠀⠀ /
		⠀⠀(\⠀ #⠀ /
		⠀/⠀⠀⠀/ὣ====================D-
		/⠀⠀⠀/⠀ \ \⠀⠀\
		( (⠀)⠀⠀⠀⠀ ) ).⠀)
		(⠀⠀)⠀⠀⠀⠀⠀( | /
		|⠀ /⠀⠀⠀⠀⠀⠀ | /
		[_] ⠀⠀⠀⠀⠀[___]                     */
	// Main Code at the Bottom
	import java.util.*;
	import java.lang.*;
	import java.io.*;
	import java.math.BigInteger; 
	public class Main {
		//Fast IO class
	    static class FastReader {
	        BufferedReader br; 
	        StringTokenizer st; 
	        public FastReader() {
	        	boolean env=System.getProperty("ONLINE_JUDGE") != null;
	        	if(!env) {
	        		try {
						br=new BufferedReader(new FileReader("src\\input.txt"));
					} catch (FileNotFoundException e) {
						e.printStackTrace();
					}
	        	}
	        	else br = new BufferedReader(new InputStreamReader(System.in)); 
	        } 
	        String next() {
	            while (st == null || !st.hasMoreElements()) {
	                try {
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) {
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken(); 
	        } 
	        int nextInt() {
	            return Integer.parseInt(next()); 
	        } 
	        long nextLong() {
	            return Long.parseLong(next()); 
	        } 
	        double nextDouble() {
	            return Double.parseDouble(next()); 
	        } 
	        String nextLine() {
	            String str = ""; 
	            try {
	                str = br.readLine(); 
	            } 
	            catch (IOException e) {
	                e.printStackTrace(); 
	            } 
	            return str; 
	        } 
	    }     
	    static long MOD=1000000000+7;
	    //Euclidean Algorithm
	    static long gcd(long A,long B){
	    	return (B==0)?A:gcd(B,A%B);
	    }
	    //Modular Exponentiation
	    static long fastExpo(long x,long n){
	        if(n==0) return 1;
	        if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD;
	        return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD;
	    }
	    //Modular Inverse
	    static long inverse(long x) {
	    	return fastExpo(x,MOD-2);
	    }
	    //Prime Number Algorithm
	    static boolean isPrime(long n){
	        if(n<=1) return false;
	        if(n<=3) return true;
	        if(n%2==0 || n%3==0) return false;
	        for(int i=5;i*i<=n;i+=6) if(n%i==0 || n%(i+2)==0) return false;
	        return true;
	    }
	    //Reverse an array
	    static void reverse(char arr[],int l,int r){
	    	while(l<r) {
	    		char tmp=arr[l];
	    		arr[l++]=arr[r];
	    		arr[r--]=tmp;
	    	}
	    }
	    //Print array
	    static void print1d(int arr[]) {
	    	out.println(Arrays.toString(arr));
	    }
	    static void print2d(int arr[][]) {
	    	for(int a[]: arr) out.println(Arrays.toString(a));
	    }
	    // Pair
	    static class pair{
	    	int x,y;
	    	pair(int a,int b){
	    		this.x=a;
	    		this.y=b;
	    	}
	    	public boolean equals(Object obj) {
	    		if(obj == null || obj.getClass()!= this.getClass()) return false;
	            pair p = (pair) obj;
	            return (this.x==p.x && this.y==p.y);
	        }
	    	public int hashCode() {
	            return Objects.hash(x,y);
	        }
	    }
	    static FastReader sc=new FastReader();
	    static PrintWriter out=new PrintWriter(System.out);  
	    //Main function(The main code starts from here
	    static int V,color[],st[],et[],timer,BLOCK=700,freq[]=new int[100000+5],cnt[];
	    static ArrayList<Integer> tour;
	    static ArrayList<Integer> graph[];
	    static void init(int n){
	        V=n;
	        color=new int[n];
	        st=new int[n];
	        et=new int[n];
	        tour=new ArrayList<>();
	        timer=0;
	        cnt=new int[n];
	        graph=new ArrayList[V];
	        for(int i=0;i<V;i++) graph[i]=new ArrayList<>();
	    }
	    static void addEdge(int src,int dest){
	        graph[src].add(dest);
	        graph[dest].add(src);
	    }
	    static void dfs(int s,int p) {
	    	st[s]=timer++;
	    	tour.add(s);
	    	for(Integer x: graph[s]) {
	    		if(x==p) continue;
	    		dfs(x,s);
	    	}
	    	et[s]=timer++;
	    	tour.add(s);
	    }
	    static class query{
	    	int l,r,k,id;
	    	query(int a,int b,int c,int d){
	    		l=a;
	    		r=b;
	    		k=c;
	    		id=d;
	    	}
	    }
	    static int N=100000+1,bit[]=new int[N+1];
	    static void add(int idx,int val) {
	    	while(idx<=N) {
	    		bit[idx]+=val;
	    		idx+=idx&-idx;
	    	}
	    }
	    static int sum(int idx) {
	    	int sum=0;
	    	while(idx>0) {
	    		sum+=bit[idx];
	    		idx-=idx&-idx;
	    	}
	    	return sum;
	    }
	    static Comparator cmp=new Comparator<query>() {
	    	public int compare(query a,query b) {
	    		if(a.l/BLOCK!=b.l/BLOCK) return a.l/BLOCK-b.l/BLOCK;
	    		if((a.l/BLOCK)%2==0) return a.r-b.r;
	    		return b.r-a.r;
	    	}
	    };
	    static void ADD(int idx) {
	    	cnt[tour.get(idx)]++;
	    	if(cnt[tour.get(idx)]==2) {
	    		if(freq[color[tour.get(idx)]]!=0) add(freq[color[tour.get(idx)]],-1);
	    		freq[color[tour.get(idx)]]++;
	    		add(freq[color[tour.get(idx)]],1);
	    	}
	    }
	    static void REMOVE(int idx) {
	    	cnt[tour.get(idx)]--;
	    	if(cnt[tour.get(idx)]==1) {
	    		add(freq[color[tour.get(idx)]],-1);
	    		freq[color[tour.get(idx)]]--;
	    		if(freq[color[tour.get(idx)]]!=0) add(freq[color[tour.get(idx)]],1);
	    	}
	    }
	    public static void main (String[] args) throws java.lang.Exception {
	    	int test=1;
	    	//test=sc.nextInt();
	    	while(test-->0){
	    		int n=sc.nextInt(),m=sc.nextInt();
	    		init(n);
	    		for(int i=0;i<n;i++) color[i]=sc.nextInt();
	    		for(int i=0;i<n-1;i++) addEdge(sc.nextInt()-1,sc.nextInt()-1);
	    		dfs(0,-1);
	    		query queries[]=new query[m];
	    		for(int i=0;i<m;i++) {
	    			int v=sc.nextInt()-1;
	    			queries[i]=new query(st[v],et[v],sc.nextInt(),i);
	    		}
	    		Arrays.parallelSort(queries,cmp);
	    		int L=0,R=-1,ans[]=new int[m];
	    		for(query q: queries) {
	    			int l=q.l,r=q.r,k=q.k,id=q.id;
	    			//extending
	    			while(L>l) ADD(--L);
	    			while(R<r) ADD(++R);
	    			//shrinking
	    			while(L<l) REMOVE(L++);
	    			while(R>r) REMOVE(R--);
	    			ans[id]=sum(N)-sum(k-1);
	    		}
	    		for(int x: ans) out.println(x+" ");
	    	}
	        out.flush();
	        out.close();
	    }
	}