You are given a tree with N nodes with every node being colored. A color is represented by an integer ranging from 1 to 10^{9}. Can you find the number of distinct colors available in a subtree rooted at the node s? 

Input Format 

The first line contains three space separated integers representing the number of nodes in the tree (N), number of queries to answer (M) and the root of the tree. 

In each of the next N-1 lines, there are two space separated integers(a b) representing an edge from node a to Node b and vice-versa.   

N lines follow: N+$i^{th} $line contains the color of the$ i^{th} $node.

M lines follow: Each line containg a single integer s.

Output Format 

Output exactly M lines, each line containing the output of the i_{th} query.

Constraints 

0 <= M <= $10^{5}$

1 <= N <= $10^{5}$

1 <= root <= N

1 <= color of the Node <=$ 10^{9}$

Example

Sample Input

4 2 1
1 2
2 4
2 3
10
20
20
30
1
2

Sample Output

3
2

Explanation

Query 1-Subtree rooted at 1 is the entire tree and colors used are 10 20 20 30 , so the answer is 3(10,20 and 30)

Query 2-Subtree rooted at 2 contains color 20 20 30, so the answer is 2(20 and 30)

Difficulty: MEDIUM_HARD
Tags: Data structures
Skill types: Data structures

Starter code:

Solutions:
class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from itertools import zip_longest
import sys

def grouper(iterable, count, fill=None):
	return zip_longest(*[iter(iterable)] * count, fillvalue=fill)

def get(ft, x):
	v = 0
	while x:
		v += ft[x]
		x -= x & -x
	return v

def update(ft, x, v):
	while x < len(ft):
		ft[x] += v
		x += x & -x
(n, m, r, *rest) = map(int, sys.stdin.read().split())
n2 = n + n - 2
n3 = n2 + n
colors = [0] + rest[n2:n3]
query = rest[n3:]
g = [set() for _ in range(n + 1)]
for (u, v) in grouper(rest[:n2], 2):
	g[u].add(v)
	g[v].add(u)
start = [0] * (n + 1)
end = [0] * (n + 1)
dfs = [r]
order = [r]
start[r] = len(order)
while dfs:
	v = dfs[-1]
	if g[v]:
		u = g[v].pop()
		g[u].discard(v)
		dfs.append(u)
		order.append(u)
		start[u] = len(order)
	else:
		dfs.pop()
		end[v] = len(order)
qs = {}
for v in query:
	qs.setdefault(end[v], []).append(v)
res = {}
bit = [0] * (n + 1)
color = {}
for v in order:
	c = colors[v]
	s = start[v]
	e = end[v]
	if c in color:
		update(bit, color[c], -1)
	update(bit, s, 1)
	color[c] = s
	if s == e and e in qs:
		t = get(bit, e)
		for u in qs[e]:
			res[u] = t - get(bit, start[u] - 1)
for q in query:
	print(res[q])


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


import math
import os
import random
import re
import sys
from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


import math
import os
import random
import re
import sys

class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenumber = dict()
multipleset = dict()
adjacent = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adjacent:
		adjacent[n1].add(n2)
	else:
		adjacent[n1] = set([n2])
	if n2 in adjacent:
		adjacent[n2].add(n1)
	else:
		adjacent[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adjacent[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenumber[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenumber[node] = 1
			multipleset[node] = set()
		for child in adjacent[node] - added:
			uniquenumber[node] += uniquenumber[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenumber[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


import math
import os
import random
import re
import sys
from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


class Stack:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.append(item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

	def pick(self):
		return self.list[len(self.list) - 1]

class Queue:

	def __init__(self):
		self.list = []

	def push(self, item):
		self.list.insert(0, item)

	def pop(self):
		return self.list.pop()

	def isEmpty(self):
		return len(self.list) == 0

class Tree:

	def __init__(self):
		self.Nodes = dict()

	def AddNode(self, label1, label2):
		if label1 not in self.Nodes:
			self.Nodes[label1] = Node(label1, set(), list(), None)
		if label2 not in self.Nodes:
			self.Nodes[label2] = Node(label2, set(), list(), None)
		node1 = self.Nodes[label1]
		node2 = self.Nodes[label2]
		node1.Nodes.append(node2)
		node2.Nodes.append(node1)

	def SetRoot(self, root):
		s = Stack()
		s.push(root)
		while not s.isEmpty():
			node = s.pick()
			if node.Nodes == None:
				s.pop()
				node.Count = len(node.Tag)
				if node.Parent != None:
					node.Parent.Tag = join(node.Parent.Tag, node.Tag)
					node.Tag = None
			else:
				for n in node.Nodes:
					n.Nodes.remove(node)
					n.Parent = node
					s.push(n)
				node.Nodes = None

	def ColorPathFromNode(self, node, color):
		l = 0
		while node is not None and node.Visited != color:
			node.Visited = color
			node.Count = node.Count + 1
			node = node.Parent
			l = l + 1

def join(x=set(), y=set()):
	if len(x) < len(y):
		return join(y, x)
	for _ in y:
		x.add(_)
	y.clear()
	return x

class Node:

	def __init__(self, label, tag, nodes, color):
		self.Label = label
		self.Tag = tag
		self.Nodes = nodes
		self.Color = color
		self.Visited = 0
		self.Parent = None
		self.Count = 0
(n, m, s) = input().split()
(n, m, s) = (int(n), int(m), int(s))
t = Tree()
for i in range(0, n - 1):
	(v1, v2) = input().split()
	(v1, v2) = (int(v1), int(v2))
	t.AddNode(v1, v2)
for i in range(0, n):
	color = int(input())
	t.Nodes[i + 1].Tag = set([color])
t.SetRoot(t.Nodes[s])
for i in range(0, m):
	x = int(input())
	print(t.Nodes[x].Count)


from collections import Counter
(n, m, root) = map(int, input().split())
uniquenum = dict()
multipleset = dict()
adj = dict()
for _ in range(n - 1):
	(n1, n2) = map(int, input().split())
	if n1 in adj:
		adj[n1].add(n2)
	else:
		adj[n1] = set([n2])
	if n2 in adj:
		adj[n2].add(n1)
	else:
		adj[n2] = set([n1])
colors = [int(input()) for _ in range(n)]
multiples = set(Counter(colors) - Counter(set(colors)))
colors.insert(0, 0)
totalcolors = len(set(colors[1:]))
stack = [root]
added = set([root])
visited = set()
while len(stack) > 0:
	node = stack[len(stack) - 1]
	if node not in visited:
		visited.add(node)
		for child in adj[node] - added:
			stack.append(child)
			added.add(child)
	else:
		if colors[node] in multiples:
			uniquenum[node] = 0
			multipleset[node] = set([colors[node]])
		else:
			uniquenum[node] = 1
			multipleset[node] = set()
		for child in adj[node] - added:
			uniquenum[node] += uniquenum[child]
			multipleset[node] |= multipleset[child]
		stack.pop()
		added.remove(node)
for _ in range(m):
	node = int(input())
	print(uniquenum[node] + len(multipleset[node]))