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.*;
import java.math.*;
public class A{
    class Node implements Comparable<Node> {
        int id;
        int l;
        int r;
        int k;
        public Node(int id,int l,int r,int k){
            this.l=l;
            this.r=r;
            this.k=k;
            this.id=id;
        }
        public int compareTo(Node c){
            int t=Long.compare(this.l/blocksize,c.l/blocksize);
            if(t!=0) return t;
            t=this.r-c.r;
            return t;
        }

    }
    void solve() {
        int n=ni(),m=ni();
        a=new int[n+1];
        color=new int[n+1];
        for(int i=1;i<=n;i++) color[i]=ni();
        while(blocksize*blocksize<n) blocksize++;
        graph=new ArrayList[n+1];
        for(int i=1;i<=n;i++) graph[i]=new ArrayList<>();
        for(int i=1;i<n;i++){
            int a=ni(),b=ni();
            graph[a].add(b); graph[b].add(a);
        }
        left=new int[n+1];
        right=new int[n+1];

        dfs(1,-1);

        Node querry[]=new Node[m+1];
        for(int i=1;i<=m;i++){
            int v=ni(),k=ni();
            querry[i]=new Node(i,left[v],right[v],k);

        }
        Arrays.sort(querry,1,m+1);
        BIT=new int[100001];
        cnt1=new int[100001];

        int l=1,r=1;
        add(1);
        long ans2[]=new long[m+1];
        for(int i=1;i<=m;i++){
            int L=querry[i].l,R=querry[i].r,k=querry[i].k;

            while(l<L){
                remove(l);
                l++;

            }
            while(l-1>=L){
                l--;
                add(l);

            }
            while(r+1<=R) {
                r++;
                add(r);

            }
            while(r>R){
                remove(r);

                r--;
            }
            int ans=query(n)-query(k-1);
            //pw.println(ans+" "+L+" "+R+" "+k);
            ans2[querry[i].id]=ans;
        }
        for(int i=1;i<=m;i++) pw.println(ans2[i]);

    }
    ArrayList<Integer> graph[];
    int left[];
    int right[];
    int a[];
    int color[];
    int blocksize=0;
    int cnt1[];

    int cc=0;
    int BIT[];
    void update(int n,int x,int val){
        for(;x<=n && x>0;x+=(x&-x)) BIT[x]+=val;
    }
    int query(int x){
        int ans=0;
        for(;x>0;x-=(x&-x)) ans+=BIT[x];
        return ans;
    }
    void add(int x){
        if(cnt1[a[x]]>0)
            update(100000,cnt1[a[x]],-1);
        cnt1[a[x]]++;
        update(100000,cnt1[a[x]],1);
    }
    void remove(int x){
        if(cnt1[a[x]]>0)
            update(100000,cnt1[a[x]],-1);
        cnt1[a[x]]--;
        update(100000,cnt1[a[x]],1);
    }
    void dfs(int v,int pr){

        left[v]=++cc;
        a[cc]=color[v];
        for(int u : graph[v]){
            if(u!=pr) dfs(u,v);
        }
        right[v]=cc;

    }
    long M=(long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
    }

    public static void main(String[] args) throws Exception { new A().run(); }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}