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.*;
public class lp{ 
static PrintWriter out = new PrintWriter(System.out);
static int mod=1000000007;
static int block=0,time=0; 
static int[] ans,ct;  
static class Query implements Comparable <Query>{
                int L,R,Index,k;
	
		public int compareTo(Query o) {
			int thing= L/block;
			int thing1= o.L/block;
			if (thing != thing1) 
				return thing-thing1;

				return R-o.R;
		}
	}
static void add(int x)
{
      ans[++ct[x]]++;      
}
static void remove(int x)
{ 
      if(ct[x]==0)
         return;
      ans[ct[x]--]--;    
}
static void queryResults(int a[], int n, Query q[], int m) 
{ 
    
    block = (int)Math.sqrt(n); 
    Arrays.sort(q); 
    int res[] = new int[m];
    ct = new int[100002];
    ans = new int[100005];

    int left = 0, right = -1;
    for (int i=0; i<m; i++) 
    { 
                        while(left > q[i].L) add(a[--left]);
			while(right < q[i].R) add(a[++right]);
			while(left < q[i].L) remove(a[left++]);
			while(right > q[i].R) remove(a[right--]);   
   
            res[q[i].Index]=ans[q[i].k];
    } 
   for(int i=0;i<m;i++)
       pn(res[i]);
} 

static void dfs(LinkedList<Integer> l[],int s,int p,int st[],int ed[],int arr[],int c[])
{

         st[s]=time++;
         arr[time-1]=c[s];
         for(Integer I : l[s])
              if(I!=p)
                 dfs(l,I,s,st,ed,arr,c);
         ed[s] = time-1;
}
static void solve() {

int n = ni();
int m = ni();
int c[] = ai(n);
int arr[] = new int[n];
int st[] = new int[n]; // start time of an index
int ed[] = new int[n]; // end time of an index
LinkedList<Integer> l[] = new LinkedList[n];

for(int i=0;i<n;i++)
   l[i] = new LinkedList();
for(int i=1;i<n;i++)
{
   int u = ni()-1;
   int v = ni()-1;
   l[u].add(v);
   l[v].add(u);
}
 dfs(l,0,-1,st,ed,arr,c);
Query q[] = new Query[m];
            for(int i=0;i<m;i++){
                    q[i] = new Query();
                    int v = ni()-1;
                    int k = ni();
                    q[i].L = st[v];
                    q[i].R = ed[v];
                    q[i].k = k;
                    q[i].Index = i;
             }
     queryResults(arr, n, q, m);

   out.flush();
}
public static void main(String[] args) throws Exception{

solve();

/* use this block when you need more recursion depth
new Thread(null, null, "Name", 999) {
            public void run() {
                try {
                    solve();
                } catch(Exception e) {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        }.start();   */
} 
static int[] ai(int n)  // it will give in array of size n
{
    int a[] = new int[n];
    for(int i=0;i<n;i++)
        a[i] = ni();
    return a;
}
static long[] al(int n)  // it will give in array of size n
{
    long a[] = new long[n];
    for(int i=0;i<n;i++)
        a[i] = nl();
    return a;
}
 
static void p(Object o)
{
   out.print(o);
}
static void pn(Object o)
{
    out.println(o);
}
static int abs(int x)
{
    return x>0 ? x : -x;
}
static long gcd(long a,long b)
{
       if(a==0)
          return b;
       if(b==0)
          return a;
       if(b%a==0)
          return a;
          return gcd(b%a,a);
}
static int count_set(int n)
{
   int c=0;
while(n>0)
{
   if(n%2==1)
     c++;
     n=n/2;
}
   return c;
}
static void subtract_1(char s[]) // it will subtract 1 from the given number.  number should be positive
{
      if(s[0]=='0') // number is zero
          return;
     int n = s.length,i=n-1;
     while(s[i]=='0')
       i--;
     s[i] = (char)((int)(s[i]-'0') + 47);
   
     for(int j=i+1;j<n;j++)
         s[j]='9';
}
static long pow(long a,long b,long md)
{ 
    long ans=1;
    while(b>0)
    {
         if(b%2==1)
           ans = (ans*a)%md;
           a = (a*a)%md;
           b = b/2;
    }
   return ans;
}
static long min(long a,long b){
 
     return a<b ? a : b;
}
static long max(long a,long b){
     return a>b ? a : b;
}
static boolean pal(String s)
{
   int n = s.length(),i1=0,i2=n-1;
 
     while(i1<i2)
     {
        if(s.charAt(i1)!=s.charAt(i2))
             return false;
             i1++; i2--;
     }
       return true;
}
static String rev(String r)
{
    String s = "";
    int i= r.length()-1;
 
    while(i>=0)
    {
        s=s+r.charAt(i);
        i--;   
    }
       return s;
}
static FastReader sc=new FastReader(); 
 
      static int ni(){
                 int x = sc.nextInt();
                 return(x);
        }
      static long nl(){
              long x = sc.nextLong();
              return(x);
         }
      static String n(){
                 String str = sc.next();
                     return(str);
       }
     static String ns(){
                 String str = sc.nextLine();
                   return(str);
      }
     static double nd(){
               double d = sc.nextDouble();
                 return(d);
       }
  static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}