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.Random;

public class D {
    
    static class Crap {
        int[] t=new int[2];
        imap m=new imap();
        
        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) {
            if(m.contains(c)) {
                int v=m.get(c);
                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 i=0; i<other.m.size; i++) {
                int c=other.m.idx2k[i];
                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 class imap {
        public int size=0;
        float load_factor;
        
        public int[] 
                bucket2idx,
                idx2k,
                idx2v,
                idx2n;
        
        public imap() {
            this(8, 0.75f);
        }
        
        public imap(int capacity, float load_factor) {
            this.load_factor=load_factor;
            bucket2idx=new int[capacity];
            Arrays.fill(bucket2idx, -1);
            
            int data_size=(int)(capacity*load_factor)+1;
            idx2k=new int[data_size];
            idx2v=new int[data_size];
            idx2n=new int[data_size];
        }
        
        private int i2hash(int i) {
            i^=(i>>>20)^(i>>>12);
            return i^(i>>>7)^(i>>>4);
        }
        
        public boolean contains(int k) {
            int idx=bucket2idx[k2bucket(k)];
            while(idx>=0) {
                if(idx2k[idx]==k) {
                    return true;
                } else {
                    idx=idx2n[idx];
                }
            }
            return false;
        }
        
        public int get(int k) {
            int idx=bucket2idx[k2bucket(k)];
            while(idx>=0) {
                if(idx2k[idx]==k) {
                    return idx2v[idx];
                } else {
                    idx=idx2n[idx];
                }
            }
            throw new IndexOutOfBoundsException();
        }
        
        public int put(int k, int v) {
            if(size>(int)(bucket2idx.length*load_factor)) {
                rehash(bucket2idx.length<<1);
            }
            
            int bucket_idx=k2bucket(k);
            int idx=bucket2idx[bucket_idx];
            if(idx>=0) {
                while(true) {
                    if(idx2k[idx]==k) {
                        int oldv=idx2v[idx];
                        idx2v[idx]=v;
                        return oldv;
                    } else if(idx2n[idx]<0) {
                        int idx2=size++;
                        idx2k[idx2]=k;
                        idx2v[idx2]=v;
                        idx2n[idx]=idx2;
                        idx2n[idx2]=-1;
                        return v;
                    } else {
                        idx=idx2n[idx];
                    }
                }
            } else {
                idx=size++;
                bucket2idx[bucket_idx]=idx;
                idx2k[idx]=k;
                idx2v[idx]=v;
                idx2n[idx]=-1;
                return v;
            }
        }

        protected int k2bucket(int k) {
            int bucket_idx=i2hash(k)%bucket2idx.length;
            if(bucket_idx<0) {
                bucket_idx=bucket2idx.length+bucket_idx;
            }
            return bucket_idx;
        }

        void rehash(int new_capacity) {
            int[] _bucket2idx=new int[new_capacity];
            Arrays.fill(_bucket2idx, -1);
            
            int data_size=(int)(new_capacity*load_factor)+1;
            int[] _idx2k=new int[data_size];
            int[] _idx2v=new int[data_size];
            int[] _idx2n=new int[data_size];
            
            int old_size=size;
            size=0;
            //swap
            int[] aux=_bucket2idx; _bucket2idx=bucket2idx; bucket2idx=aux;
            aux=_idx2k; _idx2k=idx2k; idx2k=aux;
            aux=_idx2v; _idx2v=idx2v; idx2v=aux;
            aux=_idx2n; _idx2n=idx2n; idx2n=aux;
            //populate
            for(int i=0; i<old_size; i++) {
                put(_idx2k[i], _idx2v[i]);
            }
        }
        
        public void clear() {
            if(size>0) {
                size=0;
                Arrays.fill(bucket2idx, -1);
            }
        }
        
        public void putAll(imap m) {
            int new_size=size+m.size;
            if(new_size>(int)(bucket2idx.length*load_factor)) {
                rehash((int)(1+new_size/load_factor));
            }
            for(int idx=0; idx<m.size; idx++) {
                put(m.idx2k[idx], m.idx2v[idx]);
            }
        }
        
        public String toString() {
            if(size==0)
                return "{}";

            StringBuilder sb=new StringBuilder();
            sb.append('{');
            for(int i=0; i<size; i++) {
                sb.append(idx2k[i]);
                sb.append('=');
                sb.append(idx2v[i]);
                if(i<size-1) {
                    sb.append(", ");
                }
            }
            return sb.append('}').toString();
        }
    }    
}