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:
//package round221;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Random;

public class D2 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	
	int[] color;
	int[][] g, q, qg;
	
	void solve()
	{
		int n = ni(), m = ni();
		color = na(n);
		int[] from = new int[n-1];
		int[] to = new int[n-1];
		for(int i = 0;i < n-1;i++){
			from[i] = ni()-1;
			to[i] = ni()-1;
		}
		g = packU(n, from, to);
		
		q = new int[m][];
		qg = new int[n][];
		int[] qp = new int[n];
		for(int i = 0;i < m;i++){
			int ver = ni()-1, freq = ni();
			q[i] = new int[]{ver, freq};
			qp[ver]++;
		}
		for(int i = 0;i < n;i++)qg[i] = new int[qp[i]];
		for(int i = 0;i < m;i++){
			qg[q[i][0]][--qp[q[i][0]]] = i;
		}
		
		ret = new int[m];
		f = new int[100001];
		ff = new int[100001];
		ff[0] = n;
		size = new int[n];
		dfsSize(0, -1);
		dfs(0, -1);
		
		for(int i = 0;i < m;i++){
			out.println(ret[i]);
		}
	}
	
	int[] size;
	
	void dfsSize(int cur, int par)
	{
		for(int e : g[cur]){
			if(e != par){
				dfsSize(e, cur);
				size[cur] += size[e];
			}
		}
		size[cur]++;
	}
	
	void dfs(int cur, int par)
	{
		int maxChild = -1, maxChildSize = -1;
		for(int e : g[cur]){
			if(e != par){
				if(size[e] > maxChildSize){
					maxChildSize = size[e];
					maxChild = e;
				}
			}
		}
		
		for(int e : g[cur]){
			if(e != par && e != maxChild){
				dfs(e, cur);
				dfsErase(e, cur);
			}
		}
		if(maxChild != -1)dfs(maxChild, cur);
		for(int e : g[cur]){
			if(e != par && e != maxChild){
				dfsAppend(e, cur);
			}
		}
		ff[++f[color[cur]]]++;
		
		for(int i = 0;i < qg[cur].length;i++){
			int ind = qg[cur][i];
			ret[ind] = ff[q[ind][1]];
		}
		ct++;
	}
	
	int ct = 0;
	
	void dfsAppend(int cur, int par)
	{
		for(int e : g[cur]){
			if(e != par){
				dfsAppend(e, cur);
			}
		}
		ff[++f[color[cur]]]++;
	}
	
	void dfsErase(int cur, int par)
	{
		for(int e : g[cur]){
			if(e != par){
				dfsErase(e, cur);
			}
		}
		ff[f[color[cur]]--]--;
	}
	
	static int[] f;
	static int[] ff;
	static int[] ret;
	
	static int[][] packU(int n, int[] from, int[] to) {
		int[][] g = new int[n][];
		int[] p = new int[n];
		for(int f : from)
			p[f]++;
		for(int t : to)
			p[t]++;
		for(int i = 0;i < n;i++)
			g[i] = new int[p[i]];
		for(int i = 0;i < from.length;i++){
			g[from[i]][--p[from[i]]] = to[i];
			g[to[i]][--p[to[i]]] = from[i];
		}
		return g;
	}
	
	void run() throws Exception
	{
//		int n = 100000, m = 99999;
//		Random gen = new Random();
//		StringBuilder sb = new StringBuilder();
//		sb.append(n + " ");
//		sb.append(m + " ");
////		int[][] tree = tree(n, gen);
//		for(int j =0;j < n;j++){
//			sb.append(gen.nextInt(10)+1 + " ");
//		}
//		for(int i = 0;i < n-1;i++){
//			sb.append((i+1) + " ");
//			sb.append((i+2) + " ");
//		}
////		for(int i = 0;i < n-1;i++){
////			sb.append(tree[i][0]+1 + " ");
////			sb.append(tree[i][1]+1 + " ");
////		}
//		for(int i = 0;i < m;i++){
//			sb.append(gen.nextInt(n)+1 + " ");
//			sb.append(gen.nextInt(10)+1 + " ");
//		}
//		INPUT = sb.toString();
		
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		
		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}
	
	public static int[][] tree(int n, Random gen)
	{
		int[][] e = new int[n-1][2];
		
		int[] f = new int[n];
		for(int i = 0;i < n;i++)f[i] = i; // offset
		for(int i = 0;i < n-1;i++) {
			int other = gen.nextInt(n-i)+i;
			int d = f[i]; f[i] = f[other]; f[other] = d;
		}
		
		for(int i = 0;i < n-1;i++) {
			e[i][0] = f[gen.nextInt(i+1)];
			e[i][1] = f[i+1];
		}
		
		// shuffle
		for(int i = 0;i < n-1-1;i++) {
			int other = gen.nextInt(n-1-i)+i;
			int d;
			d = e[i][0]; e[i][0] = e[other][0]; e[other][0] = d;
			d = e[i][1]; e[i][1] = e[other][1]; e[other][1] = d;
		}
		return e;
	}
	
	public static void main(String[] args) throws Exception { new D2().run(); }
	
	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;
	
	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }
	
	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}