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>).
class tree:
    def __init__(self,data,*subs):
        self._data = data
        self._subtree = list(subs)

    def __str__(self):
        a = [self._data,self._subtree]
        return str(a)

    def data(self):
        return self._data

    def is_nochild(self):
        return self._subtree == []

    def set_child(self,i,node):
        if i <= len(self._subtree):
            self._subtree[i-1] = node
        else:
            self._subtree.append(node)

    def subtree(self):
        return self._subtree

    def search(self,num):
        if vip(self._data) == num:
            return self
        else:
            if len(self._subtree) > 0:
                for i in range(len(self._subtree)):
                    if self._subtree[i].search(num):
                        return self._subtree[i].search(num)
            else:
                return None

    def ergodic(self):
        color[self._data.c] += 1
        if len(self._subtree) > 0:
            for i in range(len(self._subtree)):
                self._subtree[i].ergodic()

    def depth(self):
        if len(self._subtree) == 0:
            return 1
        a = []
        for i in range(len(self._subtree)):
            a.append(self._subtree[i].depth())
        return max(a)+1

class avltree:
    def __init__(self,data,left = None,right = None):
        self._data = data   #Data don't need to be a number, it can be anything
        self._left = left   #Left and right must be an avltree or None
        self._right = right
        self._root = None
        self.bf = 0

    def data(self):
        return self._data

    def left(self):
        return self._left

    def right(self):
        return self._right

    def root(self):
        return self._root

    def set_data(self,data):
        self._data = data

    def set_left(self,leftchild):
        self._left = leftchild

    def set_right(self,rightchild):
        self._right = rightchild

    def set_root(self,node):
        self._root = node

    def search(self,num):   #由于这是平衡二叉树，是排序树，这里是二分检索
        bt = self
        while bt is not None:
            entry = bt.data()
            if num < vip(entry):
                bt = bt.left()
            elif num > vip(entry):
                bt = bt.right()
            else:
                return entry   #You can also return True
        return None
            
    def depth(self):
        if self._left is None and self._right is None:
            return 1
        if self._left is not None:
            return 1+self._left.depth()
        if self._right is not None:
            return 1+self._right.depth()

    def insert(self,A):
        a = p = self._root
        if a is None:
            self._root = avltree(A)
            return
        pa = q = None
        while p is not None:
            if vip(A) == vip(p.data()):
                p.set_data(A)
                return
            if p.bf != 0:
                pa,a = q,p
            q = p
            if vip(A) < vip(p.data()):
                p = p.left()
            else:
                p = p.right()
        node = avltree(A)
        if vip(A) < vip(q.data()):
            q.set_left(node)
        else:
            q.set_right(node)
        if vip(A) < vip(a.data()):
            p = b = a.left()
            d = 1
        else:
            p = b = a.right()
            d = -1
        while p != node:
            if vip(A) < vip(p.data()):
                p.bf = 1
                p = p.left()
            else:
                p.bf = -1
                p = p.right()
        if a.bf == 0:
            a.bf = d
            return
        if a.bf == -d:
            a.bf = 0
            return
        if d == 1:
            if b.bf == 1:
                b = avltree.LL(a,b)
            else:
                b = avltree.LR(a,b)
        else:
            if b.bf == -1:
                b = avltree.RR(a,b)
            else:
                b = avltree.RL(a,b)
        if pa is None:
            self._root = b
        else:
            if pa.left() == a:
                pa.set_left(b)
            else:
                pa.set_right(b)
        
    @staticmethod
    def LL(a,b):
        a.set_left(b.right())
        b.set_right(a)
        a.bf = b.bf = 0
        return b

    @staticmethod
    def RR(a,b):
        a.set_right(b.left())
        b.set_left(a)
        a.bf = b.bf = 0
        return b

    @staticmethod
    def LR(a,b):
        c = b.right()
        a.set_left(c.right())
        b.set_right(c.left())
        c.set_left(b)
        c.set_right(a)
        if c.bf == 0:
            a.bf = b.bf = 0
        elif c.bf == 1:
            a.bf = -1
            b.bf = 0
        else:
            a.bf = 0
            b.bf = 1
        c.bf = 0
        return c

    @staticmethod
    def RL(a,b):
        c = b.left()
        a.set_right(c.left())
        b.set_left(c.right())
        c.set_left(a)
        c.set_right(b)
        if c.bf == 0:
            a.bf = b.bf = 0
        elif c.bf == 1:
            a.bf = 0
            b.bf = -1
        else:
            a.bf = 1
            b.bf = 0
        c.bf = 0
        return c

def setavltree(a):
    i = len(a) // 2
    A = avltree(a[i])
    A.set_root(avltree(a[i]))
    for j in range(0,i):
        A.insert(a[j])
    for j in range(i+1,len(a)):
        A.insert(a[j])
    return A


def vip(a):
    return a.num

class vertice:
    def __init__(self,num,color):
        self.num = num
        self.c = color

n,m = map(int,input().split())
aa1 = [int(i) for i in input().split()]
aa = []
color = {}
for i in range(n):
    aa.append(vertice(i+1,aa1[i]))
    color[aa1[i]] = 0
a = setavltree(aa)
a = a.root()
tr = tree(aa[0])
for i in range(n-1):
    p,q = map(int,input().split())
    te = a.search(q)
    tr.search(p).set_child(1000000000000,tree(te))
ans = []
for i in range(m):
    for j in color.keys():
        color[j] = 0
    p,q = map(int,input().split())
    o = tr.search(p)
    o.ergodic()
    kk = 0
    for j in color.keys():
        if color[j] >= q:
            kk += 1
    ans.append(str(kk))
print ('\n'.join(ans))
