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.util.*;
import java.io.*;

/**
 *
 * @author umang
 */

public class D375 {
    
    public static int mod = (int) (1e9+7);
    public static ArrayList<ArrayList<Integer>> tree;
    public static int[] color;
    public static int[] st;
    public static int[] start;
    public static int[] end;
    public static int t;    
    public static int[] ans;
    public static int block;
    public static int[] count;
    public static int[] freq;
        
    public static void dfs(int u,int p){
        start[u]=t;
        st[t++]=u;
        for(int v:tree.get(u)){
            if(v!=p) dfs(v,u);
        }
        end[u]=t-1;
    }
    
    public static void add(int x){
        count[x]++;
        freq[count[x]]++;
    }

    public static void remove(int x){
        freq[count[x]]--;
        count[x]--;
   }
    
    public static void main(String[] args) {
 
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        tree=new ArrayList<>();
        int n=in.nextInt();
        int m=in.nextInt();
        start=new int[n];
        end=new int[n];
        st=new int[n];
        color=new int[n];
        count=new int[100005];
        freq=new int[100005];

        for(int i=0;i<n;i++) tree.add(new ArrayList<>());

        for(int i=0;i<n;i++) color[i]=in.nextInt();

        for(int i=0;i<n-1;i++){
            int a=in.nextInt()-1;
            int b=in.nextInt()-1;
            tree.get(a).add(b);
            tree.get(b).add(a);
        }
        t=0;
        dfs(0, -1);
//        for(int i=0;i<n;i++) System.out.print(" "+st[i]+" ");
        ans=new int[m];
        ArrayList<Pair> p=new ArrayList<>();
        block=(int)Math.sqrt(t);
        for(int i=0;i<m;i++) p.add(new Pair(in.nextInt()-1, in.nextInt(),i));
        Collections.sort(p,new CompareTable());
        t=0;
        int cl=0;
        int cr=-1;
        for(int i=0;i<m;i++){
            Pair p1=p.get(i);
            int l=start[p1.x];
            int r=end[p1.x];
            
            while(cl>l){
                cl--;
                add(color[st[cl]]);
            }
            while(cr<r){
                cr++;
                add(color[st[cr]]);
            }
            while(cl<l){
                remove(color[st[cl]]);
                cl++;
            }
            while(cr>r){                
                remove(color[st[cr]]);
                cr--;
            }
            ans[p1.i]=freq[p1.y];
        }
        
        for(int i=0;i<m;i++) out.println(ans[i]);
        
        out.close();
    }

    static class Pair{
		int x;
		int y;
                int i;
		Pair(int x,int y,int i){
			this.x=x;
			this.y=y;
                        this.i=i;
		}
	}
    
    public static class CompareTable implements Comparator{
        public int compare(Object o1,Object o2){
            Pair p1 = (Pair) o1;
            Pair p2 = (Pair) o2;
            
            if((start[p1.x]/block)!=(start[p2.x]/block)){                
                if(start[p1.x]<start[p2.x]) return -1;
                else if(start[p1.x]>start[p2.x]) return 1;
                else return 0;
            }
            else{
                if(end[p1.x]<end[p2.x]) return -1;
                else if(end[p1.x]>end[p2.x]) return 1;
                else return 0;
            }
        }
    }
    
    public static boolean isPal(String s){
        for(int i=0, j=s.length()-1;i<=j;i++,j--){
                if(s.charAt(i)!=s.charAt(j)) return false;
        }
        return true;
    }
    public static String rev(String s){
		StringBuilder sb=new StringBuilder(s);
		sb.reverse();
		return sb.toString();
    }
    
    public static long gcd(long x,long y){
	if(x%y==0)
		return y;
	else
		return gcd(y,x%y);
    }
    
    public static int gcd(int x,int y){
	if(x%y==0)
		return y;
	else 
		return gcd(y,x%y);
    }
    
    public static long gcdExtended(long a,long b,long[] x){
        
        if(a==0){
            x[0]=0;
            x[1]=1;
            return b;
        }
        long[] y=new long[2];
        long gcd=gcdExtended(b%a, a, y);
        
        x[0]=y[1]-(b/a)*y[0];
        x[1]=y[0];
        
        return gcd;
    }
    
    public static int abs(int a,int b){
	return (int)Math.abs(a-b);
    }

    public static long abs(long a,long b){
	return (long)Math.abs(a-b);
    }
    
    public static int max(int a,int b){
	if(a>b)
		return a;
	else
		return b;
    }

    public static int min(int a,int b){
	if(a>b)
		return b;
	else 
		return a;
    }
    
    public static long max(long a,long b){
	if(a>b)
		return a;
	else
		return b;
    }

    public static long min(long a,long b){
	if(a>b)
		return b;
	else 
		return a;
    }

    public static long pow(long n,long p,long m){
	 long  result = 1;
	  if(p==0)
	    return 1;
	if (p==1)
	    return n;
	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;
	    if(result>=m)
	    result%=m;
	    p >>=1;
	    n*=n;
	    if(n>=m)
	    n%=m;
	}
	return result;
    }
    
    public static long pow(long n,long p){
	long  result = 1;
	  if(p==0)
	    return 1;
	if (p==1)
	    return n;
	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;	    
	    p >>=1;
	    n*=n;	    
	}
	return result;
    }
    
	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

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

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

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

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

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

		public long[] nextLongArray(int n) {
			long a[] = new long[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}
                
		public String readString() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

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

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
}