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.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.PriorityQueue;

public class D375 {
	
	@SuppressWarnings("unchecked")
	static class Solver {
		
		int N, M, c[], a[], IDX = 0, in[], oot[];
		ArrayList<Integer>[] adj;
		
		void dfs(int v) {
			in[v] = IDX++;
			a[in[v]] = c[v];
			for(int c : adj[v]) {
				adj[c].removeIf(x -> x == v);
				dfs(c);
			}
			oot[v] = IDX - 1;
		}
		
		void solve(FastScanner s, PrintWriter out) {
			N = s.nextInt(); M = s.nextInt(); c = s.nextIntArray(N);
			Arrays.setAll(adj = new ArrayList[N], x -> new ArrayList<>());
			for(int i = 1, u, v; i < N; i++) {
				u = s.nextInt() - 1; v = s.nextInt() - 1;
				adj[u].add(v); adj[v].add(u);
			}
			
			in = new int[N]; oot = new int[N]; a = new int[N];
			dfs(0);
			
			int SZ = 1 + (int) Math.sqrt(N + 1);
			PriorityQueue<int[]> queries = new PriorityQueue<>((a, b) -> {
				int lb = a[0] / SZ, rb = b[0] / SZ;
				if (lb == rb)
					if ((lb & 1) > 0)
						return b[1] - a[1];
					else
						return a[1] - b[1];
				return lb - rb;
			});
			
			int ans[] = new int[M];
			for(int i = 0, v, k; i < M; i++) {
				v = s.nextInt() - 1; k = s.nextInt();
				queries.add(new int[] { in[v], oot[v], k, i });
			}
			
			int[] freq = new int[100_010];
			BIT BIT = new BIT(100_010);
			
			int l = 0, r = -1, ql, qr, cur[], elem;
			while(!queries.isEmpty()) {
				cur = queries.poll(); ql = cur[0]; qr = cur[1];
				// EXPAND
				while(l > ql) {
					elem = a[--l];
					BIT.update(freq[elem]++, -1);
					BIT.update(freq[elem], 1);
				}
				while(r < qr) {
					elem = a[++r];
					BIT.update(freq[elem]++, -1);
					BIT.update(freq[elem], 1);
				}
				
				// CONTRACT
				while(l < ql) {
					elem = a[l++];
					BIT.update(freq[elem]--, -1);
					BIT.update(freq[elem], 1);
				}
				while(r > qr) {
					elem=  a[r--];
					BIT.update(freq[elem]--, -1);
					BIT.update(freq[elem], 1);

				}
				
				// ANSWER QUERY: # with frequency of >= k
				ans[cur[3]] = BIT.query(cur[2], 100010);
			}
			
			for(int x : ans) out.println(x);
		}
		
		static class BIT {
			int n;
			int[] tree;
			
			public BIT(int nn) {
				n = nn; tree = new int[n + 10];
			}
			
			int read(int i) {
				i += 5;
				int sum = 0;
				while (i > 0) {
					sum += tree[i];
					i -= i & -i;
				}
				return sum;
			}
			
			int query(int i, int j) {
				return read(j) - read(i - 1);
			}
			
			void update(int i, int val) {
				i += 5;
				while (i <= n) {
					tree[i] += val;
					i += i & -i;
				}
			}
			
		}

		
	}
	
	public static void main(String[] args) {
		FastScanner s = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		new Solver().solve(s, out);
		out.close(); s.close();
	}
	
	static class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1 << 22];
		private int curChar;
		private int numChars;
		
		public FastScanner(InputStream stream) {
			this.stream = stream;
		}
		
		public FastScanner(File f) throws FileNotFoundException {
			this(new FileInputStream(f));
		}
		
		public FastScanner(String s) {
			this.stream = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));
		}
		
		void close() {
			try {
				stream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
		
		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
		
		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
		
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		
		public String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}
		
		public String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
		
		public int[] nextIntArray(int N) {
			int[] ret = new int[N];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextInt();
			return ret;
		}
		
		public int[][] next2DIntArray(int N, int M) {
			int[][] ret = new int[N][];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextIntArray(M);
			return ret;
		}
		
		public long[] nextLongArray(int N) {
			long[] ret = new long[N];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextLong();
			return ret;
		}
		
		public long[][] next2DLongArray(int N, int M) {
			long[][] ret = new long[N][];
			for (int i = 0; i < N; i++)
				ret[i] = nextLongArray(M);
			return ret;
		}
		
		public double[] nextDoubleArray(int N) {
			double[] ret = new double[N];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextDouble();
			return ret;
		}
		
		public double[][] next2DDoubleArray(int N, int M) {
			double[][] ret = new double[N][];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextDoubleArray(M);
			return ret;
		}
		
	}
	
}