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.*;

public class Main{
	static int n;
	static int[]col;
	static LinkedList<Integer>[]adj;
	static LinkedList<int[]>[]queries;
	static int[]ans;
	
	static HashMap<Integer, Integer>[]occOfCols,occOfOcc;
	static int[]sub;
	static void dfs(int i,int par) {
		int biggestChild=-1,size=0;
		sub[i]=1;
		for(int j:adj[i]) {
			if(j==par)continue;
			dfs(j, i);
			sub[i]+=sub[j];
			
			if(sub[j]>size) {
				size=sub[j];
				biggestChild=j;
			}
		}
		if(biggestChild==-1) {//leaf
			occOfCols[i]=new HashMap<>();
			occOfCols[i].put(col[i], 1);
			occOfOcc[i]=new HashMap<>();
			occOfOcc[i].put(1, 1);
			
			
			for(int[]q:queries[i]) {
				ans[q[1]]=occOfOcc[i].getOrDefault(q[0], 0);
			}
			return;
		}
		occOfCols[i]=occOfCols[biggestChild];
		occOfOcc[i]=occOfOcc[biggestChild];
		
		for(int j:adj[i]) {
			if(j==par || j==biggestChild)continue;
			
			for(int key:occOfCols[j].keySet()) {
				int prevOcc=occOfCols[i].getOrDefault(key, 0);
				int occ=occOfCols[j].get(key);
				occOfCols[i].put(key, prevOcc+occ);
				while(occ-->0) {
					prevOcc++;
					occOfOcc[i].put(prevOcc, occOfOcc[i].getOrDefault(prevOcc, 0)+1);
				}
				
				
			}
			
		}
		int occ=occOfCols[i].getOrDefault(col[i], 0)+1;
		occOfCols[i].put(col[i], occ);
		occOfOcc[i].put(occ, occOfOcc[i].getOrDefault(occ, 0)+1);
		
		
		for(int[]q:queries[i]) {
			ans[q[1]]=occOfOcc[i].getOrDefault(q[0], 0);
		}
	}
	
	public static void main(String[] args) throws Exception{
		PrintWriter pw=new PrintWriter(System.out);
		MScanner sc = new MScanner(System.in);
		n=sc.nextInt();int m=sc.nextInt();
		col=sc.intArr(n);
		
		adj=new LinkedList[n];
		queries=new LinkedList[n];
		sub=new int[n];
		occOfCols=new HashMap[n];
		occOfOcc=new HashMap[n];
		
		for(int i=0;i<n;i++) {
			adj[i]=new LinkedList<>();
			queries[i]=new LinkedList<>();		
		}
		for(int i=0;i<n-1;i++) {
			int x=sc.nextInt()-1,y=sc.nextInt()-1;
			adj[x].add(y);
			adj[y].add(x);
		}
		ans=new int[m];
		for(int i=0;i<m;i++) {
			queries[sc.nextInt()-1].add(new int[] {sc.nextInt(),i});
		}
		dfs(0, -1);
		for(int i:ans) {
			pw.println(i);
		}
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static String arrToString(int[]x) {
		return Arrays.toString(x);
	}
	static String arrToString(long[]x) {
		return Arrays.toString(x);
	}
	static String arrToString(Integer[]x) {
		return Arrays.toString(x);
	}
	static String arrToString(Long[]x) {
		return Arrays.toString(x);
	}
}