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

public class query_on_substree {
			static int n,m,S[],E[],time;
			static ArrayList<ArrayList<Integer>> g;
			static int block,flat[],blocks[],color[],nodeF[],eleF[],FF[];
			static boolean vis[];
			static Query query[];
			static int ans[];
			static int seg[],maxn=100001;
		
			public static void main(String[] args) throws IOException{
				BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
				int t=1;
		//		Integer.parseInt(br.readLine().trim());
				StringBuilder printans=new StringBuilder();
				while(t-->0)
				{
					StringTokenizer tok=new StringTokenizer(br.readLine()," ");
					n=Integer.parseInt(tok.nextToken());
					block=700;
					blocks=new int[block+1];
					m=Integer.parseInt(tok.nextToken());
					
					g=new ArrayList<>();
					tok=new StringTokenizer(br.readLine()," ");
					color=new int[n+1];
					g.add(new ArrayList<>());
					for(int i=1;i<=n;i++) {
						g.add(new ArrayList<>());
						color[i]=Integer.parseInt(tok.nextToken());
					}vis=new boolean[n+1];
					int nn=n;
					S=new int[n+1];E=new int[n+1];flat=new int[n*2+1];query=new Query[m];nodeF=new int[100001];eleF=new int[100001];FF=new int[100001];
					while(n-->1) {
						tok=new StringTokenizer(br.readLine()," ");
						int a=Integer.parseInt(tok.nextToken());
						int b=Integer.parseInt(tok.nextToken());
						addedge(a,b);
						
					}
					
					time=1;
					
					flatthetree(1);
					
					int x = (int) (Math.ceil(Math.log(maxn) / Math.log(2))); 
					int max_size = 2 * (int) Math.pow(2, x) - 1;  
					seg=new int[max_size+1];

//					System.out.print(Arrays.toString(S)+" "+Arrays.toString(E)+" "+Arrays.toString(flat));
					int i=0;
					ans=new int[m];
					while(m-->0) {
						tok=new StringTokenizer(br.readLine()," ");
						int u=Integer.parseInt(tok.nextToken());
						int v=Integer.parseInt(tok.nextToken());
//						System.out.println(S[u]+" "+E[u]);
						query[i]=new Query(S[u],E[u],v,i);
						i++;
						
					}
					
					Arrays.sort(query,new sortfun());
//					System.out.println(Arrays.toString(E));
					for(i=0;i<query.length;i++) {
//						System.out.print(query[i].l+" ");
					}
					n=nn;
					int ml=1;int mr=0;
					for(i=0;i<query.length;i++) {
						int L=query[i].l;
						int R=query[i].r;
						int k=query[i].val;
						int pos=query[i].pos;
						while(ml>L) {
							ml--;
							add(ml);
						}
						while(ml<L) {
							remove(ml);
							ml++;
						}
						while(mr>R) {
							remove(mr);
							mr--;
						}
						while(mr<R) {
							mr++;
							add(mr);
							
						}
						
						ans[pos]=getAns(k,n);
						
						
					}
					for(i=0;i<ans.length;i++) {
						printans.append(ans[i]+"\n");
					}

					
				}
					System.out.println(printans);
				
			}
			
			static int block(int ind) {
				return (ind+block-1)/block;
			}
			
			static void add(int e) {
				int node=flat[e];
				int c=color[node];
				nodeF[node]++;
				if(nodeF[node]==2) {
					
					eleF[c]++;
					FF[eleF[c]]++;
					blocks[block(eleF[c])]++;
					FF[eleF[c]-1]--;
					blocks[block(eleF[c]-1)]--;
					
				}
			}
			static void remove(int e) {
				int node=flat[e];
				int c=color[node];
				nodeF[node]--;
				if(nodeF[node]==1) {
					
					eleF[c]--;
					FF[eleF[c]]++;
					blocks[block(eleF[c])]++;
					FF[eleF[c]+1]--;
					blocks[block(eleF[c]+1)]--;
					
				}
			}
			static int getAns(int k,int n) {
				int c=0;
				int lb=block(k);
				int ub=block(n);
				if(lb==ub) {
					for(int i=k;i<=n;i++) {
						c+=FF[i];
					}
				}
				else {
					for(int i=k;i<=lb*block;i++) {
						c+=FF[i];
					}
					for(int i=lb+1;i<ub;i++) {
						c+=blocks[i];
					}
					for(int i=ub*block+1;i<=n;i++) {
						c+=FF[i];
					}
					
				}
				return c;
			}
			static class sortfun implements Comparator<Query>{
				public int compare(Query a,Query b) {
					int x=a.l/block;
					int y=b.l/block;
					
					if(x!=y)return x-y;
					if(x%2!=0) {
						return a.r-b.r;
					}
					return b.r-a.r;
				}
			}
			static void flatthetree(int curr) {
				vis[curr]=true;
				S[curr]=time;
				flat[time++]=curr;
				for(int i=0;i<g.get(curr).size();i++) {
					if(!vis[g.get(curr).get(i)]) {
						flatthetree(g.get(curr).get(i));
					}
				}
				flat[time]=curr;
				E[curr]=time++;
				
			}
			static void printtree() {
				for(int i=0;i<=g.size();i++) {
					System.out.print(i+" ");
					for(int j=0;j<g.get(i).size();j++) {
						System.out.print(g.get(i).get(j)+" ");
							
						
					}
					System.out.println();
				}
				
			}
			static class Query{
				int l,r,val,pos;
				Query(int a,int b,int i,int c){
					l=a;r=b;val=i;pos=c;
				}
			}
			static void addedge(int a,int b) {
				g.get(a).add(b);
				g.get(b).add(a);
				
			}
			 
				
					
					
				
				
			
			
			
			

		}