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.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;

public class TreeAndQueries {
	static List<Integer>[] edges;
	static int N;
	static int[] nodeToDfs;
	static int[] dfsToNode;
	static int[] color;
	// dfs ids of the leftmost child and rightmost child of this dfs node
	// note that these form intervals [x,y], and so we can use Mo
	static int[] dfsToDfsLeft;
	static int[] dfsToDfsRight;
	static int dfsid = -1;
	
	// number of nodes with color i
	static int[] freq;
	// ff[i] = number of colors whose freq >= i
	static int[] ff;
	
	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		StringTokenizer tk;
		tk = tk(in.readLine());
		
		N = Integer.parseInt(tk.nextToken());
		int Q = Integer.parseInt(tk.nextToken());
		
		nodeToDfs = new int[N];
		dfsToNode = new int[N];
		color = new int[N];
		edges = new List[N];
		dfsToDfsLeft = new int[N];
		dfsToDfsRight = new int[N];
		ff = new int[N+1];
		for(int i=0;i<N;i++) {
			edges[i] = new ArrayList();
		}
		
		tk = tk(in.readLine());
		for(int i=0; i<N; i++) {
			color[i] = Integer.parseInt(tk.nextToken());
		}
		
		for(int i=0; i<N-1; i++) {
			tk = tk (in.readLine());
			int a = Integer.parseInt(tk.nextToken())-1;
			int b = Integer.parseInt(tk.nextToken())-1;
			edges[a].add(b);
			edges[b].add(a);
		}
		
		dfs(0, -1);
		int[] ans = new int[Q];
		Query[] queries = new Query[Q];
		for(int i=0; i<Q; i++) {
			tk = tk(in.readLine());
			int node = Integer.parseInt(tk.nextToken())-1;
			int k = Integer.parseInt(tk.nextToken());
			queries[i] = new Query(dfsToDfsLeft[nodeToDfs[node]], dfsToDfsRight[nodeToDfs[node]], k, i);
		}
		
		final int BUCKET = (int) Math.sqrt(dfsid);
		Arrays.sort(queries, new Comparator<Query>(){
			@Override
			public int compare(Query o1, Query o2) {
				int dif = o1.l / BUCKET -  o2.l / BUCKET;
				if(dif != 0) return dif;
				return o1.r - o2.r;
			}
		});
		
		int l = 0;
		int r = 0;
		int MAX = 100005;
		
		freq = new int[MAX];
		
		freq[color[dfsToNode[l]]]++;
		ff[1] = 1;
		for(Query q : queries) {
			while(l > q.l) {
				l--;
				add(l);
			}
			
			while(r < q.r) {
				r++;
				add(r);
			}
			
			while(l < q.l) {
				remove(l);
				l++;
			}
			
			while(r > q.r) {
				remove(r);
				r--;
			}
			if(q.k > N) {
				ans[q.id] = 0;
			} else 
				ans[q.id] = ff[q.k];
		}
		
		for(int qid=0; qid < Q; qid++) {
			out.println(ans[qid]);
		}
		
		out.close();
	}
	
	static void add(int dfsid) {
		int c = color[dfsToNode[dfsid]];
		// < freq[c] stays the same, > freq[c]+1 stays the same too
		ff[freq[c]+1]++;
		freq[c]++;
	}
	
	static void remove(int dfsid){ 
		int c = color[dfsToNode[dfsid]];
		// > freq[c] stays the same, < freq[c] stays the same
		ff[freq[c]]--;
		freq[c]--;
	}
	
	static void dfs(int cur, int par) {
		dfsid++;
		nodeToDfs[cur] = dfsid;
		dfsToNode[dfsid] = cur;
		
		dfsToDfsLeft[dfsid] = dfsid;
		dfsToDfsRight[dfsid] = dfsid;
		for(int child : edges[cur]) {
			if(child == par) continue;
			dfs(child, cur);
			dfsToDfsRight[nodeToDfs[cur]] = dfsToDfsRight[nodeToDfs[child]];
		}
	}
	
	static class Query {
		public int l;
		public int r;
		public int k;
		public int id;
		
		public Query(int l, int r, int k, int id) {
			this.l = l;
			this.r = r;
			this.k = k;
			this.id = id;
		}
	}
	
	static StringTokenizer tk(String s) {return new StringTokenizer(s);}
}