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.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;


public class Main {
	public static class FastReader {
			BufferedReader br;
			StringTokenizer root;
			
	 
			public FastReader() {
				br = new BufferedReader(new InputStreamReader(System.in));
			}
	 
			String next() {
				while (root == null || !root.hasMoreTokens()) {
					try {
						root = new StringTokenizer(br.readLine());
					} catch (Exception addd) {
						addd.printStackTrace();
					}
				}
				return root.nextToken();
			}
	 
			int nextInt() {
				return Integer.parseInt(next());
			}
	 
			double nextDouble() {
				return Double.parseDouble(next());
			}
	 
			long nextLong() {
				return Long.parseLong(next());
			}
	 
			String nextLine() {
				String str = "";
				try {
					str = br.readLine();
				} catch (Exception addd) {
					addd.printStackTrace();
				}
				return str;
			}
		}
	 
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static FastReader sc = new FastReader();
 
	static int mod = (int) (1e9+7),MAX=(int)(1e5+10);
	static List<Integer>[] edges;
	
	static int[] c,nodef,colf,ff,Bit;
	public static void main(String[] args) throws IOException{
		int n = sc.nextInt();
		size = (int) (Math.sqrt(n)+1);
		size = Math.min(size, n);
		int m = sc.nextInt();
		c = new int[n+1]; // color
		nodef = new int[n+1]; // node freq
		colf = new int[MAX]; // color freq
		ff = new int[n+1]; // freq of color freq
		
		Bit = new int[n+1]; // range sum query on ff
		
		for(int i=1;i<=n;++i) c[i] = sc.nextInt();
		
		edges = new ArrayList[n+1];
		for(int i=1;i<edges.length;++i) edges[i] = new ArrayList<>();
		for(int i=1;i<n;++i) {
			int u = sc.nextInt();
			int v = sc.nextInt();
			edges[u].add(v);
			edges[v].add(u);
		}
		
		time = 1;
		tree = new int[2*n+1];
		startTime = new int[n+1];
		endTime = new int[n+1];
		
	    flat(1,0);
	    
		Query[] q = new Query[m+1];
		q[0] = new Query(0,0,0,0);
		for(int i=1;i<=m;++i) {
			int v = sc.nextInt();
			int k = sc.nextInt();
			q[i] = new Query(startTime[v],endTime[v],k,i);
		}
		
		int[] ans = mo(q);
		for(int i=1;i<=m;++i) out.println(ans[i]);
		
	    out.close();
	}
	

	/*
	 * Flatten tree
	 */
	static int time;
	static int[] tree,startTime,endTime;
	private static void flat(int v,int par) {
		startTime[v] = time;
		tree[time] = v;
		++time;
		for(int child : edges[v]) 
			if(child!=par) flat(child,v);
		
		endTime[v] = time;
		tree[time] = v;
		++time;
	}

	/*
	 * Mo algo
	 */
    static int size;
	
	static int[] mo(Query[] query) {
	   int m = query.length;
	   Arrays.sort(query);
	   
	   int[] ans = new int[m];
	   int st=1,end=0; // for 1 based array

	   for(int i=1;i<query.length;++i) {
		   Query q = query[i]; 
		   while (st > q.l) {
	            st--;
	            add(st);
	        }
	        while (end < q.r) {
	            end++;
	            add(end);
	        }
	        while (st < q.l) {
	            delete(st);
	            st++;
	        }
	        while (end > q.r) {
	        	delete(end);
	            end--;
	        }
	       
	        ans[q.idx] = getAns(q.k,ff.length-1); // TODO
	   }
	   return ans;
	}
	
	private static int getAns(int k, int n) {
		if(k-1 > n) return 0;
		return query(n) - query(k-1);
	}

	private static void add(int tidx) {
		int v = tree[tidx];
		int col = c[v];
		nodef[v]++;
		if(nodef[v] == 2) {
			if(colf[col] != 0)
			update(colf[col],ff[colf[col]],ff[colf[col]]-1);
			ff[colf[col]]--;
			colf[col]++;
			if(colf[col] != 0)
			update(colf[col],ff[colf[col]],ff[colf[col]]+1);
			ff[colf[col]]++;
		}
		
	}

	private static void delete(int tidx) {
	    int v = tree[tidx];
	    int col = c[v];
	    nodef[v]--;
	    if(nodef[v] == 1) {
	    	if(colf[col] != 0)
	    	update(colf[col],ff[colf[col]],ff[colf[col]]-1);
	    	ff[colf[col]]--;
	    	colf[col]--;
	    	if(colf[col] != 0)
	    	update(colf[col],ff[colf[col]],ff[colf[col]]+1);
	    	ff[colf[col]]++;
	    }
		
	}

	static class Query implements Comparable<Query>{
		int l,r,k,idx;
		long hilbert;
		
		Query(int l,int r,int k,int idx){
			this.l = l;
			this.r = r;
			this.k = k;
			this.idx = idx;
			hilbert = gilbertOrder(l, r, 21, 0); // size = ceil(lg(n))
		}
		
		 public int compareTo(Query o) {
             if (this.hilbert < o.hilbert) {
                 return -1;
             } else if (this.hilbert > o.hilbert) {
                 return 1;
             } else {
                 return 0;
             }
         }

         long gilbertOrder(int x, int y, int pow, int rotate) {
             if (pow == 0) {
                 return 0;
             }
             int hpow = 1 << (pow - 1);
             int seg = (x < hpow) ? ((y < hpow) ? 0 : 3) : ((y < hpow) ? 1 : 2);
             seg = (seg + rotate) & 3;
             int[] rotateDelta = {3, 0, 0, 1};
             int nx = x & (x ^ hpow), ny = y & (y ^ hpow);
             int nrot = (rotate + rotateDelta[seg]) & 3;
             long subSquareSize = 1L << (2 * pow - 2);
             long ans = seg * subSquareSize;
             long add = gilbertOrder(nx, ny, pow - 1, nrot);
             ans += (seg == 1 || seg == 2) ? add : (subSquareSize - add - 1);
             return ans;
         }
	}
	
	private static int query(int i) {
		int  sum = 0;
		while(i > 0) {
			sum+=Bit[i];
			i -= -i&i;
		}
		return sum;
	}
	private static void update(int i, int from,int to) {
		int val = to - from; // change to previous to new value
		int n = Bit.length;
		while(i < n) {
			Bit[i]+=val;
			i += -i&i;
		}
	}
	

	

}