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
from functools import cmp_to_key
input = sys.stdin.readline

maxN = 100001
BLK = 700

S = [0]*maxN
T = [0]*maxN
FT = [0]*2*maxN
ans = [0]*maxN
nodeF = [0]*maxN
eleF = [0]*maxN
FF = [0]*maxN
bucket = [0]*maxN

tree = [[] for _ in range(maxN)]

def dfs(node, par):
    global timer
    S[node] = timer
    FT[timer] = node
    timer += 1
    for child in tree[node]:
        if child!=par: dfs(child, node)
    T[node] = timer
    FT[timer] = node
    timer += 1

class Query:
    def __init__(self, l, r, idx, k):
        self.l = l
        self.r = r
        self.idx = idx
        self.k = k

Q = []

def comp(a, b):
    if a.l//BLK!=b.l//BLK: return a.l//BLK<b.l//BLK
    return a.r<b.r

def getBlock(idx):
    return idx//BLK

def add(idx):
    node = FT[idx]
    nodeF[node] += 1

    if nodeF[node]==2:
        c = col[node-1]
        eleF[c] += 1
        FF[eleF[c]] += 1
        bucket[getBlock(eleF[c])] += 1
        FF[eleF[c]-1] -= 1
        bucket[getBlock(eleF[c]-1)] -= 1

def remove(idx):
    node = FT[idx]
    nodeF[node] -= 1

    if nodeF[node]==1:
        c = col[node-1]
        eleF[c] -= 1
        FF[eleF[c]] += 1
        bucket[getBlock(eleF[c])] += 1
        FF[eleF[c]+1] -= 1
        bucket[getBlock(eleF[c]+1)] -= 1

def getAns(k, n):
    ans = 0
    LB = getBlock(k)
    RB = getBlock(n)
    if LB==RB:
        for i in range(k, n+1):
            ans += FF[i]
    else:
        for i in range(k, (LB+1)*BLK):
            ans += FF[i]

        for i in range(LB+1, RB):
            ans += bucket[i]

        for i in range(RB*BLK, n+1):
            ans += FF[i]
    return ans



n, q = map(int, input().split())

col = list(map(int, input().split()))

for i in range(n-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

timer = 1
dfs(1, -1)

for i in range(q):
    a, k = map(int, input().split())
    Q.append(Query(S[a], T[a], i, k))

Q.sort(key=cmp_to_key(comp))
#print()
#for obj in Q:
#    print(obj.l, obj.r)
#print()
ML = 1; MR = 0
for i in range(q):
    L = Q[i].l
    R = Q[i].r
    k = Q[i].k
    idx = Q[i].idx

    while MR<R:
        MR += 1
        add(MR)
    while MR>R:
        remove(MR)
        MR -= 1
    while ML<L:
        remove(ML)
        ML += 1
    while ML>L:
        ML -= 1
        add(ML)

    ans[idx] = getAns(k, n)

for i in range(q):
    print(ans[i])
