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

public class Tree_Query_CF_Sqrt
{
	InputReader in;PrintWriter pw;

	int timer,n,blk,maxn=100001;
	int s[] = new int[maxn],t[] = new int[maxn],ft[] = new int[2*maxn],col[] = new int[maxn];
	int nodef[] = new int[maxn],ef[] = new int[maxn+1],ff[] = new int[maxn+1],bucket[] = new int[700];
	ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
	int tree[] = new int[4*maxn];

	int getAns(int k , int n)
	{
		int res = 0;
		int LB = k/blk;
		int RB = n/blk;
		
		if(LB == RB)
		{
			for(int i=k;i<=n;i++)
			res += ff[i];
		}
		else
		{
			for(int i=k;i<=(LB+1)*blk-1;i++)
			res += ff[i];
			
			for(int i=LB+1;i<RB;i++)
			res += bucket[i];
			
			for(int i=(RB+1)*blk;i<=n;i++)
			res += ff[i];
		}
		
		return res;
	}
	void remove(int idx)
	{
		int node = ft[idx];
		int c = col[node];
		nodef[node]--;

		if(nodef[node] == 1)
		{
			ef[c]--;
			ff[ef[c]]++;
			bucket[ef[c]/blk]++;
			
			ff[ef[c]+1]--;
			bucket[(ef[c]+1)/blk]--;
		}

	}
	void add(int idx)
	{
		int node = ft[idx];
		int c = col[node];
		nodef[node]++;

		if(nodef[node] == 2)
		{
			ef[c]++;
			ff[ef[c]]++;
			bucket[ef[c]/blk]++;
			
			ff[ef[c]-1]--;
			bucket[(ef[c]-1)/blk]--;
		}

	}
	class Query
	{
		int l,r,k,pos;
	}
	void dfs(int curr,int p)
	{
		s[curr] = timer;
		ft[timer] = curr;
		timer++;
		for(int child: list.get(curr))
			if(child!=p)
				dfs(child,curr);
		t[curr] = timer;
		ft[timer] = curr;
		timer++;
	}
	void pna()
	{
		for(int i=0;i<4*n;i++)
		{
			p(tree[i]+" ");
		}
		pn();
	}
	void solve(int test) throws Exception
	{
		n=ni();int q=ni();
		for(int i=0;i<n;i++) list.add(new ArrayList<Integer>());
		for(int i=0;i<n;i++)//color input
		{
			col[i] = ni();
		}
		for(int i=0;i<n-1;i++) //edge input
		{
			int a=ni(),b=ni();
			list.get(a-1).add(b-1);
			list.get(b-1).add(a-1);
		}

		timer=0;blk=700; //flatenning...
		dfs(0,0);
		// for(int i=0;i<2*n;i++) p(ft[i]+" ");
		// pn();
		Query query[] = new Query[q]; // query input...
		for(int i=0;i<q;i++)
		{	
			int node = ni()-1;
			query[i] = new Query();
			query[i].l = s[node];
			query[i].r = t[node];
			query[i].pos = i;
			query[i].k = ni();
		}

		Arrays.sort(query,new Comparator<Query>()
			{
				public int compare(Query a,Query b)
				{
					int x = a.l/blk;
					int y = b.l/blk;

					if(x!=y)
						return x-y;
					else
					{
						if(x%2==1)
							return a.r-b.r;
						else
							return b.r-a.r;
					}
				}
			});

		int curr_l=query[0].l,curr_r=query[0].l-1;
		int ans[] = new int[q];

		for(int i=0;i<q;i++)
		{
			int l = query[i].l,r=query[i].r,pos=query[i].pos,k=query[i].k;

			while(curr_r < r)
			{
				curr_r++;add(curr_r);
			}
			while(curr_l > l)
			{
				curr_l--;add(curr_l);
			}
			while(curr_r > r)
			{
				remove(curr_r);curr_r--;
			}
			while(curr_l < l)
			{
				remove(curr_l);curr_l++;
			}
			ans[pos] = getAns(k,n);
		}

		for(int i=0;i<q;i++)
			pn(ans[i]);
	}
	void run() throws Exception 
	{
		in = new InputReader();
		pw = new PrintWriter(System.out);
		int test = 1;
		while(test--!=0){solve(test);}
		pw.close();
	}
	public static void main(String[] args) throws Exception
	{
		new Tree_Query_CF_Sqrt().run();
	}

	void p(Object o){pw.print(o);}
	void pn(Object o){pw.println(o);}
	void pn(){pw.println();}
	void spn(Object o){System.out.println(o);};
	String nln() throws Exception {return in.nextLine();}
	int ni() throws Exception {return Integer.parseInt(in.next());}
	double nd() throws Exception {return Double.parseDouble(in.next());}
	long nl() throws Exception {return Long.parseLong(in.next());}
	class InputReader
	{
		BufferedReader br;
		StringTokenizer st;

		public InputReader()
		{
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public InputReader(String s) throws IOException
		{
			br = new BufferedReader(new FileReader(s));
		}

		String next() throws Exception
		{
			if(st==null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch(IOException e)
				{
					throw new Exception(e.toString());
				}
			}
			return st.nextToken();
		}

		String nextLine() throws Exception
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch(IOException e)
			{
				throw new Exception(e.toString());
			}
			return str;
		}
	}
}