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 implements Runnable {

	public void _main() throws IOException {
		int n = nextInt();
		int m = nextInt();
		col = new int[n];
		for (int i = 0; i < n; i++) {
			col[i] = nextInt();
		}
		for (int i = 0; i < n - 1; i++) {
			int a = nextInt() - 1;
			int b = nextInt() - 1;
			addEdge(a, b);
			addEdge(b, a);
		}
		ans = new int[m];
		for (int i = 0; i < m; i++) {
			int v = nextInt() - 1;
			queryK[i] = nextInt();
			nextQuery[i] = firstQuery[v];
			firstQuery[v] = i;
		}
		dfs(0, -1);
		for (int i = 0; i < m; i++) {
			out.println(ans[i]);
		}
	}

	final int N = 100000;

	int[] col;
	int[] ans;

	int[] firstQuery = new int[N];
	int[] nextQuery = new int[N];
	int[] queryK = new int[N];
	
	int numEdges;
	int[] firstEdge = new int[N];
	int[] nextEdge = new int[2*N];
	int[] edgeDst = new int[2*N];
	{
		Arrays.fill(firstEdge, -1);
		Arrays.fill(firstQuery, -1);
	}
	private void addEdge(int a, int b) {
		int e = numEdges++;
		nextEdge[e] = firstEdge[a];
		firstEdge[a] = e;
		edgeDst[e] = b;
	}

	private TrickySet dfs(int v, int p) {
		TrickySet cur = new TrickySet();
		cur.add(col[v], 1);
		for (int e = firstEdge[v]; e >= 0; e = nextEdge[e]) {
			int u = edgeDst[e];
			if (u == p) continue;
			TrickySet s = dfs(u, v);
			if (s.size() < cur.size()) {
				cur.merge(s);
			} else {
				s.merge(cur);
				cur = s;
			}
		}
		for (int q = firstQuery[v]; q >= 0; q = nextQuery[q]) {
			ans[q] = cur.tree.sum(queryK[q], N);
		}
		return cur;
	}

	class TrickySet {
		Map<Integer, Integer> colToAm = new HashMap<Integer, Integer>();
		FenwickTree tree = new FenwickTree();
		int size;

		void add(int c, int howMany) {
			int am = 0;
			if (colToAm.containsKey(c)) {
				am = colToAm.get(c);
				tree.add(am, -1);				
			}
			am += howMany;
			size += howMany;
			colToAm.put(c, am);
			tree.add(am, 1);
		}
		int size() {
			return size;
		}
		void merge(TrickySet other) {
			for (Map.Entry<Integer, Integer> e : other.colToAm.entrySet()) {
				add(e.getKey(), e.getValue());
			}
		}
	}

	class FenwickTree {
		int[] a = new int[5];
		int[] s = new int[5];

		void ensureCapacity(int n) {
			if (a.length >= n) return;
			int[] na = new int[n];
			s = new int[n];
			for (int i = 0; i < a.length; i++) {
				int x = a[i];
				na[i] = x;
				add(i, x);
			}
			a = na;
		}

		void add(int pos, int val) {
			ensureCapacity(pos + 1);
			a[pos] += val;
			while (pos < s.length) {
				s[pos] += val;
				pos |= pos + 1;
			}
		}
		int sum(int l, int r) {
			return sum(r) - sum(l - 1);
		}
		int sum(int r) {
			r = Math.min(r, a.length - 1);
			int res = 0;
			while (r >= 0) {
				res += s[r];
				r = (r & (r + 1)) - 1;
			}
			return res;
		}
	}


	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	private String next() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String rl = in.readLine();
			if (rl == null)
				return null;
			st = new StringTokenizer(rl);
		}
		return st.nextToken();
	}

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

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

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

	public static void main(String[] args) {
		Locale.setDefault(Locale.UK);
		new Thread(new Main()).start();
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			//in = new BufferedReader(new FileReader("a.in"));
			//out = new PrintWriter(new FileWriter("a.out"));

			_main();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(202);
		}
	}

}