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.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

public class TreeAndQueries
{
    static int array[],tree[],start[],end[],freq[],ffreq[],ans[],node[];//,fwt[];
    static int block=800;
    static int fastq[];
    static ArrayList<Integer> al[];static int timer=1;static Query qt[];
    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

    static class Query
    {
        int l,r,index,kp;
        Query(int l,int r,int index)
        {
            this.l=start[l];
            this.r=end[l];
            this.kp=r;
            this.index=index;
        }
    }
    public static void main(String args[])throws IOException
    {
        Reader sc=new Reader();
        int n=sc.nextInt();
        int m=sc.nextInt();
        array=new int[n+1];
        //block=(int)Math.sqrt(n);
        al=new ArrayList[n+1];
        tree=new int[2*n+1];
        start=new int[n+1];
        node=new int[n+1];
        end=new int[n+1];
        fastq=new int[100001];
        ans=new int[m];
        qt=new Query[m];
        int maxn=0;
        for(int i=1;i<=n;i++)
        {
            array[i]=sc.nextInt();
            al[i]=new ArrayList<>();
            maxn=Math.max(maxn,array[i]);
        }
        freq=new int[maxn+1];
        ffreq=new int[n+1];
        for(int i=0;i<n-1;i++)
        {
            AddEdge(sc.nextInt(),sc.nextInt());
        }
        dfs(1,-1);
        int k=0;
        for(int i=0;i<m;i++)
        {
            qt[i]=new Query(sc.nextInt(),sc.nextInt(),k);
            k++;
        }
        Arrays.sort(qt, (o1, o2) -> o1.l/block!=o2.l/block?o1.l-o2.l:o1.l/block%2==0?o1.r-o2.r:o2.r-o1.r);
        int ml=1,mr=0;
        for(int i=0;i<qt.length;i++)
        {
            int l=qt[i].l;
            int r=qt[i].r;
            int kt=qt[i].kp;
            int ind=qt[i].index;
            while(ml>l)
            {
                ml--;
                add(ml);
            }

            while(mr<r)
            {
                mr++;
                add(mr);
            }

            while (ml<l)
            {
                remove(ml);
                ml++;
            }

            while(mr>r)
            {
                remove(mr);
                mr--;
            }
            ans[ind]=findsm(kt,n);
        }

        for(int i=0;i<ans.length;i++)
        {
            System.out.print(ans[i]+" ");
        }
    }
    public static int findsm(int a,int b)
    {
        int res=0;
        int lb=getBlockS(a);
        int rb=getBlockS(b);

        if(lb==rb)
        {
            for(int i=a;i<=b;i++)
            {
                res+=ffreq[i];
            }
        }
        else
        {
            for(int i=a;i<=lb*block;i++)
            {
                res+=ffreq[i];
            }
            for(int i=lb+1;i<rb;i++)
            {
                res+=fastq[i];
            }
            for(int i=rb*block+1;i<=b;i++)
            {
                res+=ffreq[i];
            }
        }
        return res;
    }
    public static void AddEdge(int src,int dest)
    {
        al[src].add(dest);
        al[dest].add(src);
    }
    public static void dfs(int src,int parent)
    {
        tree[timer]=src;
        start[src]=timer++;
        for(Integer a:al[src])
        {
            if(a!=parent)
            {
                dfs(a,src);
            }
        }
        tree[timer]=src;
        end[src]=timer++;
    }
    public static void add(int pos)
    {
        node[tree[pos]]++;
        int temp=array[tree[pos]];
        if(node[tree[pos]]==2)
        {
            freq[temp]++;
            ffreq[freq[temp]]++;
            fastq[getBlockS(freq[temp])]++;
            if(freq[array[tree[pos]]]-1!=0) {
                ffreq[freq[temp] - 1]--;
                fastq[getBlockS(freq[temp]-1)]--;
            }
        }
    }
    public static void remove(int pos)
    {
        node[tree[pos]]--;
        int temp=array[tree[pos]];
        if(node[tree[pos]]==1)
        {
            ffreq[freq[temp]]--;
            fastq[getBlockS(freq[temp])]--;
            freq[temp]--;
            if(freq[array[tree[pos]]]!=0) {
                ffreq[freq[temp]]++;
                fastq[getBlockS(freq[temp])]++;
            }
        }
    }
    public static int getBlockS(int pos)
    {
        return (pos+block-1)/block;
    }
}

/*
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
 */