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 *c*<sub class="lower-index">*v*</sub>. 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 *v*<sub class="lower-index">*j*</sub>, *k*<sub class="lower-index">*j*</sub>. The answer to query *v*<sub class="lower-index">*j*</sub>, *k*<sub class="lower-index">*j*</sub> is the number of such colors of vertices *x*, that the subtree of vertex *v*<sub class="lower-index">*j*</sub> contains at least *k*<sub class="lower-index">*j*</sub> 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).
The first line contains two integers *n* and *m* (2 ≤ *n* ≤ 10<sup class="upper-index">5</sup>; 1 ≤ *m* ≤ 10<sup class="upper-index">5</sup>). The next line contains a sequence of integers *c*<sub class="lower-index">1</sub>, *c*<sub class="lower-index">2</sub>, ..., *c*<sub class="lower-index">*n*</sub> (1 ≤ *c*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">5</sup>). The next *n* - 1 lines contain the edges of the tree. The *i*-th line contains the numbers *a*<sub class="lower-index">*i*</sub>, *b*<sub class="lower-index">*i*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub>, *b*<sub class="lower-index">*i*</sub> ≤ *n*; *a*<sub class="lower-index">*i*</sub> ≠ *b*<sub class="lower-index">*i*</sub>) — the vertices connected by an edge of the tree.

Next *m* lines contain the queries. The *j*-th line contains two integers *v*<sub class="lower-index">*j*</sub>, *k*<sub class="lower-index">*j*</sub> (1 ≤ *v*<sub class="lower-index">*j*</sub> ≤ *n*; 1 ≤ *k*<sub class="lower-index">*j*</sub> ≤ 10<sup class="upper-index">5</sup>).
import sys
readline=sys.stdin.readline

def Mo(N,Q,query):
    D=max(1,int(N/Q**.5))
    mo=[[] for d in range((N+D-1)//D+1)]
    for q,(l,r) in enumerate(query):
        mo[l//D].append(q)
    retu=[]
    for d in range((N+D-1)//D+1):
        retu+=sorted(mo[d],reverse=d%2,key=lambda q:query[q][1])
    return retu

N,Q=map(int,readline().split())
C=list(map(int,readline().split()))
graph=[[] for x in range(N)]
for _ in range(N-1):
    a,b=map(int,readline().split())
    a-=1;b-=1
    graph[a].append(b)
    graph[b].append(a)

seen=[False]*N
finished=[False]*N
stack=[0]
tour=[]
size=[1]*N
while stack:
    x=stack.pop()
    if not seen[x]:
        tour.append(x)
        seen[x]=True
        stack.append(x)
        for y in graph[x]:
            if not seen[y]:
                stack.append(y)
    elif not finished[x]:
        finished[x]=True
        for y in graph[x]:
            if finished[y]:
                size[x]+=size[y]
query=[]
for m in range(Q):
    v,k=map(int,readline().split())
    v-=1
    query.append((v,k))
idx=[None]*N
for i in range(N):
    idx[tour[i]]=i
M=max(C)
C=[C[x] for x in tour]
L,R=0,0
cnt=[0]*(M+1)
freq=[0]*(N+1)
ans_lst=[None]*Q
for q in Mo(N,Q,[(idx[v],idx[v]+size[v]) for v,_ in query]):
    v,k=query[q]
    l,r=idx[v],idx[v]+size[v]
    while l<L:
        L-=1
        freq[cnt[C[L]]+1]+=1
        cnt[C[L]]+=1
    while R<r:
        cnt[C[R]]
        freq[cnt[C[R]]+1]+=1
        cnt[C[R]]+=1
        R+=1
    while L<l:
        cnt[C[L]]-=1
        freq[cnt[C[L]]+1]-=1
        L+=1
    while r<R:
        R-=1
        cnt[C[R]]-=1
        freq[cnt[C[R]]+1]-=1
    ans_lst[q]=freq[k]
print(*ans_lst,sep="\n")