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.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;


public class ProblemD {
	
	static class Query {
		int idx;
		int req;
		Query(int i, int k) {
			idx = i;
			req = k;
		}
	}
	
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		int n = in.nextInt();
		int m = in.nextInt();
		c = new int[n];
		for (int i = 0 ; i < n ; i++) {
			c[i] = in.nextInt();
			N = Math.max(N, c[i]);
		}
		N = Math.max(N, n);
		
		graph = new List[n];
		for (int i = 0 ; i < n ; i++) {
			graph[i] = new ArrayList<Integer>();
		}
		for (int i = 0 ; i < n-1 ; i++) {
			int a = in.nextInt()-1;
			int b = in.nextInt()-1;
			graph[a].add(b);
			graph[b].add(a);
		}
		children = new int[n];
		cdfs(0, -1);
		
		
		q = new List[n];
		for (int i = 0 ; i < n ; i++) {
			q[i] = new ArrayList<Query>();
		}
		for (int i = 0 ; i < m ; i++) {
			int v = in.nextInt()-1;
			int k = in.nextInt();
			q[v].add(new Query(i, k));
		}

		ans = new long[m];
		dfs(0, -1);
		for (int i = 0 ; i < m ; i++) {
			out.println(ans[i]);
		}
		out.flush();
	}
	
	static int[] c;
	static List<Integer>[] graph;
	static List<Query>[] q;
	static long[] ans;
	static int N;
	static int[] children;
	
	static int cdfs(int now, int parent) {
		int cnt = 1;
		for (int next : graph[now]) {
			if (next == parent) {
				continue;
			}
			cnt += cdfs(next, now);
		}
		children[now] = cnt;
		return cnt;
	}
	
	static DataSet dfs(int now, int parent) {
		int N = children[now]+1;
		DataSet data = new DataSet(N);
		for (int next : graph[now]) {
			if (next == parent) {
				continue;
			}
			DataSet child = dfs(next, now);
			if (data.countMap.size() > child.countMap.size()) {
				data.merge(child);
			} else {
				child.merge(data);
				data = child;
			}
		}
		data.add(c[now], 1);
		for (Query query : q[now]) {
			if (query.req > N) {
				ans[query.idx] = 0; 
			} else {
				ans[query.idx] = data.bit.sum(query.req, N);
			}
		}
		return data;
	}

	static class DataSet {
		Map<Integer,Integer> countMap;
		FenwickTree bit; 
		DataSet(int cnt) {
			countMap = new HashMap<Integer,Integer>();
			bit = new FenwickTree();
		}
		
		void add(int color, int value) {
			int ge = 0;
			if (countMap.containsKey(color)) {
				ge = countMap.get(color);
				bit.add(ge, -1);
			}
			bit.add(ge+value, 1);
			countMap.put(color, ge+value);
		}
		
		void merge(DataSet other) {
			for (int color : other.countMap.keySet()) {
				add(color, other.countMap.get(color));
			}
		}
	}
	
	static void merge(TreeMap<Integer,Integer> map, TreeMap<Integer,Integer> child) {
		for (int c : child.keySet()) {
			if (!map.containsKey(c)) {
				map.put(c, child.get(c));
			} else {
				map.put(c, map.get(c) + child.get(c));
			}
		}
	}
	
	static class InputReader {
	    private InputStream stream;
	    private byte[] buf = new byte[1024];
	    private int curChar;
	    private int numChars;
	    private SpaceCharFilter filter;

	    public InputReader(InputStream stream) {
	          this.stream = stream;
	    }

	    public int next() {
	          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++];
	    }

	    public int nextInt() {
	          int c = next();
	          while (isSpaceChar(c))
	                c = next();
	          int sgn = 1;
	          if (c == '-') {
	                sgn = -1;
	                c = next();
	          }
	          int res = 0;
	          do {
	                if (c < '0' || c > '9')
	                      throw new InputMismatchException();
	                res *= 10;
	                res += c - '0';
	                c = next();
	          } while (!isSpaceChar(c));
	          return res * sgn;
	    }

	    public boolean isSpaceChar(int c) {
	          if (filter != null)
	                return filter.isSpaceChar(c);
	          return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	    }

	    public interface SpaceCharFilter {
	          public boolean isSpaceChar(int ch);
	    }
	}
	
	static 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;
		}
	}
	
	public static void debug(Object... o) {
		System.err.println(Arrays.deepToString(o));
	}
}