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 D {
	FastReader scn;
	PrintWriter out;
	String INPUT = "";

	int block;

	public class query implements Comparable<query> {
		int l, r, val, ind;

		query(int x, int y, int z, int i) {
			l = x;
			r = y;
			val = z;
			ind = i;
		}

		public int compareTo(query o) {
			if (this.l / block != o.l / block) {
				return this.l / block - o.l / block;
			}
			return this.r - o.r;
		}

		public String toString() {
			return l + " " + r + " " + val + " " + ind;
		}
	}

	int time = 0;

	void solve() {
		int n = scn.nextInt(), Q = scn.nextInt(), max = 0;
		block = (int) Math.sqrt(n);
		int[] arr = scn.nextIntArray(n);
		arr = compress(arr);
		for (int i = 0; i < n; i++) {
			max = Math.max(max, arr[i] + 1);
		}
		int[] from = new int[n - 1], to = new int[n - 1];
		for (int i = 0; i < n - 1; i++) {
			from[i] = scn.nextInt() - 1;
			to[i] = scn.nextInt() - 1;
		}
		int[][] g = packU(n, from, to);
		int[] order = new int[n], start = new int[n], end = new int[n];
		dfs(g, order, start, end, 0, -1);

		query[] qr = new query[Q];
		for (int i = 0; i < Q; i++) {
			int u = scn.nextInt() - 1, val = scn.nextInt();
			int l = start[u], r = end[u];
			qr[i] = new query(l, r, val, i);
		}

		Arrays.sort(qr);
		int[] ans = new int[Q], count = new int[n + 1], color = new int[max];
		int curL = 0, curR = -1; // indexes[0, N)
		for (query q : qr) {
			while (curR < q.r) {
				curR++;
				// WORK: add
				color[arr[order[curR]]]++;
				count[color[arr[order[curR]]]]++;
			}
			while (curL > q.l) {
				curL--;
				// WORK: add
				color[arr[order[curL]]]++;
				count[color[arr[order[curL]]]]++;
			}
			while (curR > q.r) {
				count[color[arr[order[curR]]]]--;
				color[arr[order[curR]]]--;
				// WORK: remove
				curR--;
			}
			while (curL < q.l) {
				count[color[arr[order[curL]]]]--;
				color[arr[order[curL]]]--;
				// WORK: remove
				curL++;
			}
			if (q.val < count.length) {
				ans[q.ind] = count[q.val]; // req ans from work
			}
		}

		for (int z : ans) {
			out.println(z);
		}
	}

	void dfs(int[][] g, int[] order, int[] start, int[] end, int u, int p) {
		order[time] = u;
		start[u] = time;
		time++;
		for (int v : g[u]) {
			if (v != p) {
				dfs(g, order, start, end, v, u);
			}
		}
		end[u] = time - 1;
	}

	int[] compress(int[] arr) {
		int n = arr.length;
		int[] rv = new int[n];
		int[][] temp = new int[n][2];
		for (int i = 0; i < n; i++) {
			temp[i][0] = arr[i];
			temp[i][1] = i;
		}
		Arrays.sort(temp, (o1, o2) -> o1[0] - o2[0]);
		int pos = 1;
		rv[temp[0][1]] = pos++;
		for (int i = 1; i < n; i++) {
			if (temp[i][0] != temp[i - 1][0]) {
				rv[temp[i][1]] = pos++;
			} else {
				rv[temp[i][1]] = rv[temp[i - 1][1]];
			}
		}

		return rv;
	}

	int[][] packU(int n, int[] from, int[] to) {
		int[][] g = new int[n][];
		int[] p = new int[n];
		for (int f : from)
			p[f]++;
		for (int t : to)
			p[t]++;
		for (int i = 0; i < n; i++)
			g[i] = new int[p[i]];
		for (int i = 0; i < from.length; i++) {
			g[from[i]][--p[from[i]]] = to[i];
			g[to[i]][--p[to[i]]] = from[i];
		}
		return g;
	}

	void run() throws Exception {
		long time = System.currentTimeMillis();
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		out = new PrintWriter(System.out);
		scn = new FastReader(oj);
		solve();
		out.flush();
		if (!oj) {
			System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
		}
	}

	public static void main(String[] args) throws Exception {
		new D().run();
	}

	class FastReader {
		InputStream is;

		public FastReader(boolean onlineJudge) {
			is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		}

		byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		int readByte() {
			if (lenbuf == -1)
				throw new InputMismatchException();
			if (ptrbuf >= lenbuf) {
				ptrbuf = 0;
				try {
					lenbuf = is.read(inbuf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return -1;
			}
			return inbuf[ptrbuf++];
		}

		boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b))
				;
			return b;
		}

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

		char nextChar() {
			return (char) skip();
		}

		String next() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		String nextLine() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		char[] next(int n) {
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while (p < n && !(isSpaceChar(b))) {
				buf[p++] = (char) b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		int nextInt() {
			int num = 0, b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		long nextLong() {
			long num = 0;
			int b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		char[][] nextMatrix(int n, int m) {
			char[][] map = new char[n][];
			for (int i = 0; i < n; i++)
				map[i] = next(m);
			return map;
		}

		int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		int[][] next2DInt(int n, int m) {
			int[][] arr = new int[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextIntArray(m);
			}
			return arr;
		}

		long[][] next2DLong(int n, int m) {
			long[][] arr = new long[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextLongArray(m);
			}
			return arr;
		}

		int[] shuffle(int[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				arr[i] = arr[i] ^ arr[j];
				arr[j] = arr[i] ^ arr[j];
				arr[i] = arr[i] ^ arr[j];
			}
			return arr;
		}
	}
}