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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class D {
    
    static class Crap {
        int[] t=new int[2];
        Map<Integer, Integer> m=new HashMap<Integer, Integer>();
        
        int size() {
            return m.size();
        }
        
        private void tadd(int i, int j) {
            i++;
            if(i>=t.length) {
                int[] tmp=new int[Math.max(t.length<<1,i+1)];
                System.arraycopy(t, 0, tmp, 0, t.length);
                t=tmp;
            }
            while(i>0) {
                t[i]+=j;
                i-=Integer.lowestOneBit(i);
            }
        }
        
        private int tget(int i) {
            i++;
            int ret=0;
            while(i<t.length) {
                ret+=t[i];
                i+=Integer.lowestOneBit(i);
            }
            return ret;
        }
        
        void add(int c, int cnt) {
            Integer v=m.get(c);
            if(v!=null) {
                tadd(v,-1);
                v+=cnt;
                m.put(c, v);
                tadd(v,1);
            } else {
                m.put(c, cnt);
                tadd(cnt,1);
            }
        }
        
        Crap union(Crap other) {
            if(other.size()>size()) {
                return other.union(this);
            }
            
            for(int c: other.m.keySet()) {
                int cnt=other.m.get(c);
                add(c, cnt);
            }
            
            return this;
        }
        
        int size(int x) {
            return tget(x);
        }
    }
    
    static int n, m;
    static int[] v2c, q2v, q2x;
    
    static int[][] t, v2q;
    static int[] v2cnt, v2p, ret;
    
    static void visit(int v) {
        if(v>0&&v2cnt[v]==1) {
            v2cnt[v]--;
            for (int i=0; i<t[v].length; i++) {
                int pv=t[v][i];
                if(v2cnt[pv]>0) {
                    v2p[v]=pv;
                    v2cnt[pv]--;
                    visit(pv);
                    break;
                }
            }
        }
    }
    
    static void e2tree(int[] e1, int[] e2) {
        int n=e1.length+1;
        v2cnt=new int[n];
        for (int i=0; i<n-1; i++) {
            v2cnt[e1[i]]++;
            v2cnt[e2[i]]++;
        }
        
        t=new int[n][];
        for (int i=0; i<n; i++) {
            t[i]=new int[v2cnt[i]];
        }
        for (int i=0; i<n-1; i++) {
            int v1=e1[i], v2=e2[i];
            t[v1][--v2cnt[v1]]=v2;
            t[v2][--v2cnt[v2]]=v1;
        }
        for (int i=0; i<n-1; i++) {
            v2cnt[e1[i]]++;
            v2cnt[e2[i]]++;
        }
        
        v2p=new int[n]; //vertex->parent vertex
        Arrays.fill(v2p, -1);

        for (int i=1; i<n; i++) {
            if(v2cnt[i]==1) {
                visit(i);
            }
        }
    }
    
    
    static void prepare_queries() {
        int[] v2qcnt=new int[n];
        for (int i=0; i<q2v.length; i++) {
            v2qcnt[q2v[i]]++;
        }
        
        v2q=new int[n][];
        for (int i=0; i<n; i++) {
            v2q[i]=new int[v2qcnt[i]];
        }
        for (int i=0; i<q2v.length; i++) {
            int v=q2v[i];
            v2q[v][--v2qcnt[v]]=i;
        }
    }
    
    
    static Crap visit(int v, Crap cr) {
        for (int i=0; i<t[v].length; i++) {
            int cv=t[v][i];
            if(cv!=v2p[v]) {
                if(v2q[cv].length==0) {
                    cr=visit(cv, cr);
                } else {
                    Crap cr2=new Crap();
                    
                    cr2=visit(cv, cr2);
                    
                    for (int j=0; j<v2q[cv].length; j++) {
                        int q=v2q[cv][j];
                        int x=q2x[q];
                        
                        ret[q]=cr2.size(x);
                    }
                    
                    cr=cr.union(cr2);
                }
            }
        }
        cr.add(v2c[v],1);
        return cr;
    }
    
    static void visit_tree() {
        ret=new int[m];
        
        Crap cr=new Crap();
        cr=visit(0,cr);
        
        for (int j=0; j<v2q[0].length; j++) {
            int q=v2q[0][j];
            int x=q2x[q];
            
            ret[q]=cr.size(x);
        }
    }
    
    static void compute(int[] e1, int[] e2) {
        e2tree(e1, e2);
        prepare_queries();
        visit_tree();
    }

    
    
    
    static StringBuilder sb=new StringBuilder();
    static void parse(String l, int[] here) {
        sb.setLength(0);
        int len=l.length(), j=0;
        for (int i=0; i<len; i++) {
            char c=l.charAt(i);
            if(c==' ') {
                here[j++]=Integer.parseInt(sb.toString())-1;
                sb.setLength(0);
            } else {
                sb.append(c);
            }
        }
        if(sb.length()>0) {
            here[j++]=Integer.parseInt(sb.toString())-1;
        }
    }
    
    static void run_stream(InputStream ins) throws IOException {
        BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
        String[] s=r.readLine().split(" ");
        n=Integer.parseInt(s[0]);
        m=Integer.parseInt(s[1]);
        
        v2c=new int[n];
        parse(r.readLine(), v2c);
        
        int[] e1=new int[n-1], e2=new int[n-1];
        for (int i=0; i<n-1; i++) {
            String l=r.readLine();
            int space=l.indexOf(' ');
            e1[i]=Integer.parseInt(l.substring(0, space))-1;
            e2[i]=Integer.parseInt(l.substring(space+1, l.length()))-1;
        }
        
        q2v=new int[m];
        q2x=new int[m];
        for (int i=0; i<m; i++) {
            String l=r.readLine();
            int space=l.indexOf(' ');
            q2v[i]=Integer.parseInt(l.substring(0, space))-1;
            q2x[i]=Integer.parseInt(l.substring(space+1, l.length()));
        }
        
        compute(e1,e2);
        sb.setLength(0);
        for (int i=0; i<m; i++) {
            sb.append(ret[i]+"\n");
        }
        System.out.print(sb.toString());
    }

    public static void main(String[] args) throws IOException {
        run_stream(System.in);
        //test_tree();
        //test_random_tree();
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    static Random r=new Random();
    static int[][] random_tree(int n) {
        int[][] ret=new int[n][];
        for (int i=0, j=1; i<n; i++) {
            int cnt=Math.min(n-j+1, 10);
            int k=r.nextInt(cnt);
            if(k==0&&i==0) {
                k++;
            }
            ret[i]=new int[k];
            for (int l=0; l<k; l++) {
                ret[i][l]=j++;
            }
        }
        
        return ret;
    }
    
    static void tree2edges(int[][] t, int[] e1, int[] e2) {
        int k=0;
        for (int i=0; i<t.length; i++) {
            for (int j=0; j<t[i].length; j++) {
                if(r.nextBoolean()) {
                    e1[k]=i; e2[k]=t[i][j];
                } else {
                    e2[k]=i; e1[k]=t[i][j];
                }
                k++;
            }
        }
    }
    
    static void test_random_tree() {
        test_tree(random_tree(1000));
    }

    static void test_tree() {
        int[][] t=new int[][] {{1,2,3,4},{},{5},{},{6},{7,8,9},{},{},{},{}};
        test_tree(t);
    }
    
    static void test_tree(int[][] t) {
        int[] e1=new int[t.length-1], e2=new int[t.length-1];
        tree2edges(t, e1, e2);
        e2tree(e1, e2);
        
        boolean error=false;
        if(t.length!=D.t.length) {
            System.out.println("lens don't match, extected: "+t.length+" got "+D.t.length);
        } else {
            for (int i=0; i<D.t.length; i++) {
                if(!Arrays.equals(t[i], D.t[i])) {
                    System.out.println("at "+i+" expected: "+Arrays.toString(t[i])+ " got: "+Arrays.toString(D.t[i]));
                    error=true;
                }
            }
            if(!error) {
                System.out.println("all good");
            }
        }
    }
    
    
    
//    static int remap(int i, int j) {
//        i2j[i]=j++;
//        for (int k=0; k<t[i].length; k++) {
//            if(t[i][k]!=v2p[i]) {
//                j+=remap(i, j);
//            }
//        }
//        return j;
//    }
//    
//    static void remap() {
//        int n=t.length;
//        Arrays.fill(v2cnt, 0);
//        for (int i=1; i<n; i++) {
//            v2cnt[v2p[i]]+=t[i].length-1;
//        }
//        
//        i2j=new int[n];
//        remap(0,0);
//        j2i=new int[n];
//        for (int i=0; i<n; i++) {
//            j2i[i2j[i]]=i;
//        }
//    }
//    
//    static void partition_colors(int[] c) {
//        int n=c.length, maxc=-1;
//        for (int i=0; i<n; i++) {
//            if(c[i]>maxc) {
//                maxc=c[i];
//            }
//        }
//        
//        int[] c2vcnt=new int[maxc+1];
//        for (int i=0; i<n; i++) {
//            c2vcnt[c[i]]++;
//        }
//        c2j=new int[maxc+1][];
//        for (int i=0; i<c2j.length; i++) {
//            c2j[i]=new int[c2vcnt[i]];
//        }
//        for (int i=0; i<n; i++) {
//            int ci=c[i];
//            c2j[ci][--c2vcnt[ci]]=i2j[i];
//        }
//        for (int i=0; i<c2j.length; i++) {
//            Arrays.sort(c2j[i]);
//        }
//    }
    
    
}