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

public class Main {
	static ArrayList<ArrayList<Integer>> adj;
	static int[] col;
	static ArrayList<Querry> arrQuerry;
	static int[] in, out, ft;
	static int timer, BLK = 400;
	static int[] ans, nodeCount, colCount, colCountFreq;
	static int[] bucket;
	
	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		// Tree and Queries - Code forces
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter o = new PrintWriter(new BufferedOutputStream(System.out), true);
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int q = Integer.parseInt(st.nextToken());
		
		col = new int[n+1];
		st = new StringTokenizer(br.readLine());
		for(int i=1; i<=n; i++) {
			col[i] = Integer.parseInt(st.nextToken());
		}
		
		adj = new ArrayList<>();
		for(int i=0; i<=n; i++) {
			adj.add(new ArrayList<>());
		}
		for(int i=1; i<=n-1; i++) {
			st = new StringTokenizer(br.readLine());
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			adj.get(a).add(b);
			adj.get(b).add(a);
		}
		
		in = new int[n+1];
		out = new int[n+1];
		ft = new int[2*n+1];
		timer = 1;
		dfs(1,-1);
		
		arrQuerry = new ArrayList<>();
		for(int i=1; i<=q; i++) {
			st = new StringTokenizer(br.readLine());
			int a = Integer.parseInt(st.nextToken());
			int k = Integer.parseInt(st.nextToken());
			arrQuerry.add(new Querry(in[a], out[a], i, k));
		}
		
		Collections.sort(arrQuerry, new Comparator<Querry>() {
			public int compare(Querry q1, Querry q2) {
				int blk1 = q1.l/BLK;
				int blk2 = q2.l/BLK;
				if(blk1 != blk2) {
					return blk1-blk2;
				}
				if(blk1%2 == 1) {
					return q1.r-q2.r;
				}
				return q2.r-q1.r;
			}
		});
		
		ans = new int[q+1];
		nodeCount = new int[n+1];
		colCount = new int[100001];
		bucket = new int[400];
		colCountFreq = new int[n+1];
		
		int ml = 1;
		int mr = 0;
		for(int i=0; i<q; i++) {
			Querry querry = arrQuerry.get(i);
			int l = querry.l;
			int r = querry.r;
			int index = querry.index;
			int k = querry.k;
			
			while(mr<r) {
				mr += 1;
				add(mr);
			}
			while(ml>l) {
				ml -= 1;
				add(ml);
			}
			while(mr>r) {
				remove(mr);
				mr -= 1;
			}
			while(ml<l) {
				remove(ml);
				ml += 1;
			}
			
			ans[index] = getAns(k, n);
		}
		
		StringBuilder sb = new StringBuilder();
		for(int i=1; i<=q; i++) {
			sb.append(ans[i]).append("\n");
		}
		o.println(sb.toString());
	}
	
	public static int getIndex(int i) {
		return (i+BLK-1)/BLK;
	}
	
	public static int getAns(int k, int n) {
		int count = 0;
		int lb = getIndex(k);
		int rb = getIndex(n);
		
		if(lb==rb) {
			for(int i=k; i<=n; i++) {
				count += colCountFreq[i];
			}
			return count;
		}
		
		for(int i=k; i<=lb*BLK; i++) {
			count += colCountFreq[i];
		}
		for(int i=lb+1; i<rb; i++) {
			count += bucket[i];
		}
		for(int i=(rb-1)*BLK+1; i<=n; i++) {
			count += colCountFreq[i];
		}
		return count;
	}
	
	public static void add(int i) {
		int node = ft[i];
		nodeCount[node] += 1;
		if(nodeCount[node] == 2) {
			int c = col[node];
			colCountFreq[colCount[c]] -= 1;
			bucket[getIndex(colCount[c])] -= 1;
			colCount[c] += 1;
			colCountFreq[colCount[c]] += 1;
			bucket[getIndex(colCount[c])] += 1;
		}
	}
	
	public static void remove(int i) {
		int node = ft[i];
		nodeCount[node] -= 1;
		if(nodeCount[node] == 1) {
			int c = col[node];
			colCountFreq[colCount[c]] -= 1;
			bucket[getIndex(colCount[c])] -= 1;
			colCount[c] -= 1;
			colCountFreq[colCount[c]] += 1;
			bucket[getIndex(colCount[c])] += 1;
		}
	}
	
	public static void dfs(int i, int parent) {
		in[i] = timer;
		ft[timer] = i;
		timer += 1;
		
		for(int j: adj.get(i)) {
			if(j != parent) {
				dfs(j, i);
			}			
		}
		
		out[i] = timer;
		ft[timer] = i;
		timer += 1;
	}
	
	static class Querry{
		int l;
		int r;
		int index;
		int k;
		Querry(int l, int r, int i, int k){
			this.l = l;
			this.r = r;
			this.index = i;
			this.k = k;
		}
	}

}