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 TreeandQuery_Mo
{
    static int C [] = new int [100010]; // Colour
    static int A [] = new int [100010]; // Compressed Tree into Array
    static query Q[] = new query[100010]; // To store Queries
    static int ANS[] = new int [100010]; // To store Answers
    static int CUR[]=new int[100010]; // To store number of colors with a specific frequency of occurrence.
    static int CNT[]=new int[100010]; // To store frequency of each colour .
    static int S[] = new int[100010]; // To store Start Time in Euler Array
    static int F[] = new int[100010]; // To store Finish Time in Euler Array
    static int N,q,SQ,time=0;
    static ArrayList<ArrayList<Integer>> adjList = new ArrayList<ArrayList<Integer>>(); // ADJLIST
    public static void main(String[]args)
    {
        InputReader1 sc = new InputReader1(System.in);
        N = sc.nextInt(); q = sc.nextInt();
        for(int i=0;i<=N;i++)adjList.add(new ArrayList<Integer>());
        int sq = (int)Math.sqrt(N);
        for(int i=1;i<=N;i++) C[i] = sc.nextInt();
        for(int i=1;i<N;i++)
        {
            int u = sc.nextInt() , v = sc.nextInt();
            adjList.get(u).add(v); adjList.get(v).add(u);
        }
        dfs(1,-1);
        for(int i=1;i<=q;i++)
        {
            int node = sc.nextInt() , val = sc.nextInt();
            Q[i] = new query(S[node],F[node],val,i,S[node]/sq);
            /* For each query ,
             * L , R is S[node] and F[node] in the compressed array
             * Minimum Frequency of Any color is stored in val
             * Query Index is stored as i
             * Block Number is Query L value / Sqrt(N) as done above
             */
        }
        Arrays.sort(Q,1,q+1); // Sort by block number and for same block sort in asc order or R value
        int curl=1 , curr = 0;
        for(int i=1;i<=q;i++)
        {
            int l = Q[i].l;
            int r = Q[i].r;
            while(curl>l)
            {
                --curl;
                CNT[A[curl]]++;
                CUR[CNT[A[curl]]]++;
            }
            while(curr<r)
            {
                ++curr;
                CNT[A[curr]]++;
                CUR[CNT[A[curr]]]++;
            }
            while(l>curl)
            {
                CNT[A[curl]]--;
                CUR[CNT[A[curl]]+1]--;
                curl++;
            }
            while(r<curr)
            {
                CNT[A[curr]]--;
                CUR[CNT[A[curr]]+1]--;
                curr--;
            }
            // N ROOT N because each pointer moves maximum sqrt(N) times for each query
            ANS[Q[i].idx]=CUR[Q[i].val];
        }
        for(int i=1;i<=q;i++)
            System.out.println(ANS[i]);
    }

    static void dfs(int node ,int parent)
    {
        S[node] = ++time;
        A[time] = C[node]; // Store the colour!
        for(int next : adjList.get(node))
        {
            if(next!=parent) dfs(next,node);
        }
        F[node] = time;
    }
}
class query implements Comparable<query>
{
    int l , r, val,idx ,bl;
    public query(int l , int r, int val , int idx ,int bl)
    {
        this.l = l;
        this.r = r;
        this.val=val;
        this.idx=idx;
        this.bl=bl;
    }

    public int compareTo(query q)
    {
        if(this.bl!=q.bl) return this.bl-q.bl;
        else return this.r-q.r;
    }
}
class InputReader1 
{

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader1(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c & 15;
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public long nextLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c & 15;
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String next() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public String nextLine() {
        int c = read();
        //while (c != '\n' && c != '\r' && c != '\t' && c != -1)
        //c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (c != '\n' && c != '\r' && c != '\t' && c != -1);
        return res.toString();
    }

    public static boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

}