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 Solution
{
    static int color[];
    static int freqcolor[];
    static int freqnode[];
    static int freqoffreq[];
    static int start[];
    static int end[];
    static int flatten[];
    static int bucket[];
    static ArrayList<Integer> adj[];
    static Query arr[];
    static int BLOCK;
    static int timer;
    static boolean visited[];
    
    public static void main(String ag[])throws Exception
    {
        Reader sc=new Reader();
        int i,j,k;
        int N=sc.nextInt();
        int M=sc.nextInt();
        
        adj=new ArrayList[N+1];
        start=new int[N+1];
        end=new int[N+1];
        color=new int[N+1];
        freqcolor=new int[100000+1];
        freqnode=new int[N+1];
        freqoffreq=new int[100000+1];
        flatten=new int[2*N+1];
        visited=new boolean[N+1];
        bucket=new int[100000+1];
        arr=new Query[M];
        BLOCK=600;
        timer=1;
        
        for(i=1;i<=N;i++)
        color[i]=sc.nextInt();
        
        for(i=0;i<=N;i++)
        adj[i]=new ArrayList<>();
        
        for(i=1;i<N;i++)
        {
            int a=sc.nextInt();
            int b=sc.nextInt();
            adj[a].add(b);
            adj[b].add(a);
        }
        
        DFS(1);
        
        for(i=1;i<=M;i++)
        {
            int node=sc.nextInt();
            int color=sc.nextInt();
            arr[i-1]=new Query(start[node],end[node],i,color);
        }
        Arrays.sort(arr,new myComparator());
        
        int ans[]=new int[M+1];
        int mL=1;
        int mR=0;
        for(i=0;i<M;i++)
        {
            int L=arr[i].l;
            int R=arr[i].r;
            int ID=arr[i].id;
            int C=arr[i].c;
            
            while(mL>L)
            {
                mL--;
                add(mL);
            }
            while(mR<R)
            {
                mR++;
                add(mR);
            }
            while(mL<L)
            {
                remove(mL);
                mL++;
            }
            while(mR>R)
            {
                remove(mR);
                mR--;
            }
            
            ans[ID]=find(C,N);
        }
        
        PrintWriter printr=new PrintWriter(System.out); 
        for(i=1;i<=M;i++)
        printr.println(ans[i]);
        //sb.append(ans[i]+"\n");
        
        printr.flush();
        
    }
    public static void DFS(int node)
    {
        visited[node]=true;
        start[node]=timer;
        flatten[timer]=node;
        timer++;
        
        Iterator<Integer> itr=adj[node].iterator();
        while(itr.hasNext())
        {
            int X=itr.next();
            if(!visited[X])
            DFS(X);
        }
        
        end[node]=timer;
        flatten[timer]=node;
        timer++;
    }
    public static void add(int pos)
    {
        int node=flatten[pos];
        int c=color[node];
        freqnode[node]++;
        
        if(freqnode[node]==2)
        {
            freqcolor[c]++;
            freqoffreq[freqcolor[c]]++;
            bucket[get(freqcolor[c])]++;
            freqoffreq[freqcolor[c]-1]--;
            bucket[get(freqcolor[c]-1)]--;
        }
    }
    public static void remove(int pos)
    {
        int node=flatten[pos];
        int c=color[node];
        freqnode[node]--;
        
        if(freqnode[node]==1)
        {
            freqcolor[c]--;
            freqoffreq[freqcolor[c]]++;
            bucket[get(freqcolor[c])]++;
            freqoffreq[freqcolor[c]+1]--;
            bucket[get(freqcolor[c]+1)]--;
        }
    }
    public static int find(int C,int N)
    {
        int LB=get(C);
        int RB=get(N);
        int i;
        int ans=0;
        if(LB==RB)
        {
            for(i=C;i<=N;i++)
            ans+=freqoffreq[i];
        }
        else 
        {
            for(i=C;i<=LB*(BLOCK);i++)
            ans+=freqoffreq[i];
            
            for(i=LB+1;i<RB;i++)
            ans+=bucket[i];
            
            
            for(i=(RB)*(BLOCK)+1;i<=N;i++)
            ans+=freqoffreq[i];
        }
        return ans;
    }
    public static int get(int index)
    {
        return ((index+BLOCK-1)/BLOCK);
    }
    static class Query
    {
        int l,r,id,c;
        Query(int L,int R,int ID,int C)
        {
            l=L; r=R; id=ID; c=C;
        }
    }
    static class myComparator implements Comparator<Query>
    {
        public int compare(Query A,Query B)
        {
            if(A.l/BLOCK!=B.l/BLOCK)
            return A.l-B.l;
            else if((A.l/BLOCK)%2==0)
            return A.r-B.r;
            else 
            return B.r-A.r;
        }
    }
    
    static class Reader 
    { 
        final private int BUFFER_SIZE = 1 << 16; 
        private DataInputStream din; 
        private byte[] buffer; 
        private int bufferPointer, bytesRead; 
  
        public Reader() 
        { 
            din = new DataInputStream(System.in); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } 
  
        public Reader(String file_name) throws IOException 
        { 
            din = new DataInputStream(new FileInputStream(file_name)); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } 
  
        public String readLine() throws IOException 
        { 
            byte[] buf = new byte[64]; // line length 
            int cnt = 0, c; 
            while ((c = read()) != -1) 
            { 
                if (c == '\n') 
                    break; 
                buf[cnt++] = (byte) c; 
            } 
            return new String(buf, 0, cnt); 
        } 
  
        public int nextInt() throws IOException 
        { 
            int ret = 0; 
            byte c = read(); 
            while (c <= ' ') 
                c = read(); 
            boolean neg = (c == '-'); 
            if (neg) 
                c = read(); 
            do
            { 
                ret = ret * 10 + c - '0'; 
            }  while ((c = read()) >= '0' && c <= '9'); 
  
            if (neg) 
                return -ret; 
            return ret; 
        } 
  
        public long nextLong() throws IOException 
        { 
            long ret = 0; 
            byte c = read(); 
            while (c <= ' ') 
                c = read(); 
            boolean neg = (c == '-'); 
            if (neg) 
                c = read(); 
            do { 
                ret = ret * 10 + c - '0'; 
            } 
            while ((c = read()) >= '0' && c <= '9'); 
            if (neg) 
                return -ret; 
            return ret; 
        } 
  
        public double nextDouble() throws IOException 
        { 
            double ret = 0, div = 1; 
            byte c = read(); 
            while (c <= ' ') 
                c = read(); 
            boolean neg = (c == '-'); 
            if (neg) 
                c = read(); 
  
            do { 
                ret = ret * 10 + c - '0'; 
            } 
            while ((c = read()) >= '0' && c <= '9'); 
  
            if (c == '.') 
            { 
                while ((c = read()) >= '0' && c <= '9') 
                { 
                    ret += (c - '0') / (div *= 10); 
                } 
            } 
  
            if (neg) 
                return -ret; 
            return ret; 
        } 
  
        private void fillBuffer() throws IOException 
        { 
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); 
            if (bytesRead == -1) 
                buffer[0] = -1; 
        } 
  
        private byte read() throws IOException 
        { 
            if (bufferPointer == bytesRead) 
                fillBuffer(); 
            return buffer[bufferPointer++]; 
        } 
  
        public void close() throws IOException 
        { 
            if (din == null) 
                return; 
            din.close(); 
        } 
    } 
}