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.text.*;
public class Main{
    //SOLUTION BEGIN
    //Into the Hardware Mode
    void pre() throws Exception{}
    void solve(int TC)throws Exception {
        int n = ni(), m = ni();
        HashMap<Integer, Integer>[] qu = new HashMap[n];
        for(int i = 0; i< n; i++)qu[i] = new HashMap<>();
        int[] from = new int[n-1], to = new int[n-1];
        int[] col = new int[n];
        for(int i = 0; i< n; i++)col[i] = ni()-1;
        for(int i = 0; i< n-1; i++){
            from[i] = ni()-1;to[i] = ni()-1;
        }
        SegTree t = new SegTree(100000), f = new SegTree(100000);
        int[][] g = makeU(n, from, to);
        for(int i = 0; i< m; i++){
            int u = ni()-1, ff = ni();
            qu[u].put(i, ff);
        }
        int[] ans = new int[m];
        int[] sub = new int[n];
        sub(g, sub, 0, -1);
        dfs(g, qu, t, f, col, sub, ans, 0, -1, true);
        for(int i:ans)pn(i);
    }
    void flip(int[][] g, SegTree t, SegTree f, int[] col, int u, int p, int delta){
        f.u(t.sum(col[u], col[u]), -1);
        t.u(col[u], delta);
        f.u(t.sum(col[u], col[u]), 1);
        for(int v:g[u])
            if(v != p)flip(g, t, f, col, v, u, delta);
    }
    void dfs(int[][] g,HashMap<Integer, Integer>[] qu, SegTree t, SegTree f, int[] col, int[] sub, int[] ans, int u, int p, boolean keep){
        int hc = -1;
        for(int v:g[u]){
            if(v == p)continue;
            if(hc == -1 || sub[v] > sub[hc])hc = v;
        }
        for(int v:g[u]){
            if(v == p || v == hc)continue;
            dfs(g, qu, t, f, col, sub, ans, v, u, false);
        }
        if(hc != -1)dfs(g, qu, t, f, col, sub, ans, hc, u, true);
        for(int v:g[u]){
            if(v == p || v == hc)continue;
            flip(g, t, f, col, v, u, 1);
        }
        f.u(t.sum(col[u], col[u]), -1);
        t.u(col[u], 1);
        f.u(t.sum(col[u], col[u]), 1);

        for(Map.Entry<Integer, Integer> e:qu[u].entrySet()) ans[e.getKey()] = f.geq(e.getValue());

        if(!keep)flip(g, t, f, col, u, p, -1);
    }
    int sub(int[][] g, int[] sub, int u, int p){
        sub[u]++;
        for(int v:g[u])if(v != p)sub[u] += sub(g, sub, v, u);
        return sub[u];
    }
    int[][] makeU(int n, int[]from, int[] to){
        int[][] g = new int[n][];int[] cnt = new int[n];
        for(int i:from)cnt[i]++;
        for(int i:to)cnt[i]++;
        for(int i = 0; i< n; i++)g[i] = new int[cnt[i]];
        for(int i = 0; i< from.length; i++){
            g[from[i]][--cnt[from[i]]] = to[i];
            g[to[i]][--cnt[to[i]]] = from[i];
        }
        return g;
    }
    class SegTree{
        int m = 1;
        int[] t;
        public SegTree(int n){
            while(m<n)m<<=1;
            t = new int[m<<1];
        }
        void u(int p, int a){
            t[p+=m] += a;
            for(p>>=1; p>0; p>>=1)t[p] = t[p<<1]+t[p<<1|1];
        }
        int geq(int x){
            return sum(x, m-1);
        }
        int sum(int l, int r){
            return s(l, r, 0, m-1, 1);
        }
        int s(int l, int r, int ll, int rr, int i){
            if(l == ll && r == rr)return t[i];
            int mid = (ll+rr)>>1;
            if(r <= mid)return s(l, r, ll, mid, i<<1);
            else if(l > mid)return s(l, r, mid+1, rr, i<<1|1);
            else return s(l, mid, ll, mid, i<<1)+s(mid+1, r, mid+1, rr, i<<1|1);
        }
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    void exit(boolean b){if(!b)System.exit(0);}
    long IINF = (long)1e15;
    final int INF = (int)1e9+2, MX = (int)2e6+5;
    DecimalFormat df = new DecimalFormat("0.00000000000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-8;
    static boolean multipleTC = false, memory = false, fileIO = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        long ct = System.currentTimeMillis();
        if(fileIO){
            in = new FastReader("");
            out = new PrintWriter("");
        }else {
            in = new FastReader();
            out = new PrintWriter(System.out);
        }
        //Solution Credits: Taranpreet Singh
        int T = (multipleTC)?ni():1;
        pre();
        for(int t = 1; t<= T; t++)solve(t);
        out.flush();
        out.close();
        System.err.println(System.currentTimeMillis()-ct);
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    int find(int[] set, int u){return set[u] = (set[u] == u?u:find(set, set[u]));}
    int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next() throws Exception{
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    throw new Exception(e.toString());
                }
            }
            return st.nextToken();
        }

        String nextLine() throws Exception{
            String str;
            try{
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }
            return str;
        }
    }
}