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

public class Round221D {

	public static LinkedList<Integer>[] adj;
	public static ArrayList<Integer> euler;
	public static int[] left;
	public static int[] right;
	public static final int block_size = 500;
	
	public static void dfs(int curr, int pr) {
		left[curr] = euler.size();
		euler.add(curr);
		for(Integer x : adj[curr]) {
			if(x != pr) {
				dfs(x, curr);
			}
		}
		right[curr] = euler.size() - 1;
	}
	public static final int max = (int)1e5+2;
	public static int[] color_count;
	public static int[] color;
	public static int[] suffix;
	
	public static void add(int pos) {
		int node = euler.get(pos);
		int x = color[node];
		color_count[x]++;
		suffix[color_count[x]]++;
	}
	
	public static void remove(int pos) {		
		int node = euler.get(pos);
		int x = color[node];
		suffix[color_count[x]]--;
		color_count[x]--;
	}
	
	public static void solve() {
		int n = s.nextInt();
		int q = s.nextInt();
		color = new int[n];
		for(int i = 0; i < n; i++) {
			color[i] = s.nextInt();
		}
		adj = new LinkedList[n];
		euler = new ArrayList<Integer>();
		left = new int[n];
		right = new int[n];
		color_count = new int[max];
		suffix = new int[max];
		for(int i = 0; i < n; i++) {
			adj[i] = new LinkedList<Integer>();
		}
		for(int i = 0; i < n - 1; i++) {
			int u = s.nextInt() - 1;
			int v = s.nextInt() - 1;
			adj[u].add(v);
			adj[v].add(u);
		}
		dfs(0, 0);
		Query[] ask = new Query[q];
		for(int i = 0; i < q; i++) {
			int x = s.nextInt() - 1;
			int k = s.nextInt();
			ask[i] = new Query(left[x], right[x], k, i);
		}
		Arrays.sort(ask);
		int currL = 0;
		int currR = -1;
		int[] answers = new int[q];
		for(int i = 0; i < q; i++) {
			int ql = ask[i].l;
			int qr = ask[i].r;
			while(currR < qr) {
				currR++;
				add(currR);
			}
			while(currR > qr) {
				remove(currR);
				currR--;
			}
			while(currL < ql) {
				remove(currL);
				currL++;
			}
			while(currL > ql) {
				currL--;
				add(currL);
			}
			answers[ask[i].idx] = suffix[ask[i].k];
		}
		for(int i = 0; i < q; i++) {
			out.print(answers[i]+" ");
		}
	}

	public static class Query implements Comparable<Query>{
		int l;
		int r;
		int idx;
		int block_number;
		int k;
		public Query(int l, int r, int k,int idx) {
			this.l = l;
			this.r = r;
			block_number = l/block_size;
			this.k = k;
			this.idx = idx;
		}
		public int compareTo(Query x) {
			if(this.block_number == x.block_number) {
				return this.r - x.r;
			}
			return this.block_number - x.block_number;
		}
	}
	
	public static void main(String[] args) {
		out = new PrintWriter(new BufferedOutputStream(System.out));
		s = new FastReader();
		solve();
		out.close();
	}

	public static FastReader s;
	public static PrintWriter out;

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	
}