You are playing a strange game with Li Chen. You have a tree with n nodes drawn on a piece of paper. All nodes are unlabeled and distinguishable. Each of you independently labeled the vertices from 1 to n. Neither of you know the other's labelling of the tree.

You and Li Chen each chose a subtree (i.e., a connected subgraph) in that tree. Your subtree consists of the vertices labeled x_1, x_2, …, x_{k_1} in your labeling, Li Chen's subtree consists of the vertices labeled y_1, y_2, …, y_{k_2} in his labeling. The values of x_1, x_2, …, x_{k_1} and y_1, y_2, …, y_{k_2} are known to both of you.

<image> The picture shows two labelings of a possible tree: yours on the left and Li Chen's on the right. The selected trees are highlighted. There are two common nodes.

You want to determine whether your subtrees have at least one common vertex. Luckily, your friend Andrew knows both labelings of the tree. You can ask Andrew at most 5 questions, each of which is in one of the following two forms: 

  * A x: Andrew will look at vertex x in your labeling and tell you the number of this vertex in Li Chen's labeling. 
  * B y: Andrew will look at vertex y in Li Chen's labeling and tell you the number of this vertex in your labeling. 



Determine whether the two subtrees have at least one common vertex after asking some questions. If there is at least one common vertex, determine one of your labels for any of the common vertices.

Interaction

Each test consists of several test cases.

The first line of input contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.

For each testcase, your program should interact in the following format.

The first line contains a single integer n (1 ≤ n ≤ 1 000) — the number of nodes in the tree.

Each of the next n-1 lines contains two integers a_i and b_i (1≤ a_i, b_i≤ n) — the edges of the tree, indicating an edge between node a_i and b_i according to your labeling of the nodes.

The next line contains a single integer k_1 (1 ≤ k_1 ≤ n) — the number of nodes in your subtree.

The next line contains k_1 distinct integers x_1,x_2,…,x_{k_1} (1 ≤ x_i ≤ n) — the indices of the nodes in your subtree, according to your labeling. It is guaranteed that these vertices form a subtree.

The next line contains a single integer k_2 (1 ≤ k_2 ≤ n) — the number of nodes in Li Chen's subtree.

The next line contains k_2 distinct integers y_1, y_2, …, y_{k_2} (1 ≤ y_i ≤ n) — the indices (according to Li Chen's labeling) of the nodes in Li Chen's subtree. It is guaranteed that these vertices form a subtree according to Li Chen's labelling of the tree's nodes.

Test cases will be provided one by one, so you must complete interacting with the previous test (i.e. by printing out a common node or -1 if there is not such node) to start receiving the next one.

You can ask the Andrew two different types of questions. 

  * You can print "A x" (1 ≤ x ≤ n). Andrew will look at vertex x in your labeling and respond to you with the number of this vertex in Li Chen's labeling. 
  * You can print "B y" (1 ≤ y ≤ n). Andrew will look at vertex y in Li Chen's labeling and respond to you with the number of this vertex in your labeling. 



You may only ask at most 5 questions per tree.

When you are ready to answer, print "C s", where s is your label of a vertex that is common to both subtrees, or -1, if no such vertex exists. Printing the answer does not count as a question. Remember to flush your answer to start receiving the next test case. 

After printing a question do not forget to print end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

  * fflush(stdout) or cout.flush() in C++; 
  * System.out.flush() in Java; 
  * flush(output) in Pascal; 
  * stdout.flush() in Python; 
  * see documentation for other languages. 



If the judge responds with -1, it means that you asked more queries than allowed, or asked an invalid query. Your program should immediately terminate (for example, by calling exit(0)). You will receive Wrong Answer; it means that you asked more queries than allowed, or asked an invalid query. If you ignore this, you can get other verdicts since your program will continue to read from a closed stream.

Hack Format

To hack, use the following format. Note that you can only hack with one test case.

The first line should contain a single integer t (t=1).

The second line should contain a single integer n (1 ≤ n ≤ 1 000).

The third line should contain n integers p_1, p_2, …, p_n (1≤ p_i≤ n) — a permutation of 1 to n. This encodes the labels that Li Chen chose for his tree. In particular, Li Chen chose label p_i for the node you labeled i.

Each of the next n-1 lines should contain two integers a_i and b_i (1≤ a_i, b_i≤ n). These edges should form a tree.

The next line should contain a single integer k_1 (1 ≤ k_1 ≤ n).

The next line should contain k_1 distinct integers x_1,x_2,…,x_{k_1} (1 ≤ x_i ≤ n). These vertices should form a subtree.

The next line should contain a single integer k_2 (1 ≤ k_2 ≤ n).

The next line should contain k_2 distinct integers y_1, y_2, …, y_{k_2} (1 ≤ y_i ≤ n). These vertices should form a subtree in Li Chen's tree according to the permutation above.

Examples

Input

1
3
1 2
2 3
1
1
1
2
2
1


Output

A 1
B 2
C 1


Input

2
6
1 2
1 3
1 4
4 5
4 6
4
1 3 4 5
3
3 5 2
3
6
1 2
1 3
1 4
4 5
4 6
3
1 2 3
3
4 1 6
5


Output

B 2
C 1
A 1
C -1

Note

For the first sample, Li Chen's hidden permutation is [2, 3, 1], and for the second, his hidden permutation is [5, 3, 2, 4, 1, 6] for both cases.

In the first sample, there is a tree with three nodes in a line. On the top, is how you labeled the tree and the subtree you chose, and the bottom is how Li Chen labeled the tree and the subtree he chose: 

<image>

In the first question, you ask Andrew to look at node 1 in your labelling and tell you the label of it in Li Chen's labelling. Andrew responds with 2. At this point, you know that both of your subtrees contain the same node (i.e. node 1 according to your labeling), so you can output "C 1" and finish. However, you can also ask Andrew to look at node 2 in Li Chen's labelling and tell you the label of it in your labelling. Andrew responds with 1 (this step was given with the only reason — to show you how to ask questions).

For the second sample, there are two test cases. The first looks is the one from the statement: 

<image>

We first ask "B 2", and Andrew will tell us 3. In this case, we know 3 is a common vertex, and moreover, any subtree with size 3 that contains node 3 must contain node 1 as well, so we can output either "C 1" or "C 3" as our answer.

In the second case in the second sample, the situation looks as follows: 

<image>

In this case, you know that the only subtree of size 3 that doesn't contain node 1 is subtree 4,5,6. You ask Andrew for the label of node 1 in Li Chen's labelling and Andrew says 5. In this case, you know that Li Chen's subtree doesn't contain node 1, so his subtree must be consist of the nodes 4,5,6 (in your labelling), thus the two subtrees have no common nodes.

Source: codeforces | Difficulty: HARD
Tags: Tree algorithms

Graph traversal


Solutions:
import sys
from collections import deque
t = int(sys.stdin.readline())
for i in range(t):
	n = int(sys.stdin.readline())
	EDGE = [list(map(int, sys.stdin.readline().split())) for i in range(n - 1)]
	k1 = int(sys.stdin.readline())
	X = list(map(int, sys.stdin.readline().split()))
	k2 = int(sys.stdin.readline())
	Y = list(map(int, sys.stdin.readline().split()))
	print('B', Y[0], flush=True)
	yans = int(input())
	if yans in X:
		print('C', yans, flush=True)
	else:
		QUE = deque([yans])
		EDGELIST = [[] for i in range(n + 1)]
		for (i, j) in EDGE:
			EDGELIST[i].append(j)
			EDGELIST[j].append(i)
		checked = [0] * (n + 1)
		XLIST = [0] * (n + 1)
		for xver in X:
			XLIST[xver] = 1
		while QUE:
			now = QUE.pop()
			checked[now] = 1
			for ver in EDGELIST[now]:
				if checked[ver] == 1:
					continue
				else:
					QUE.append(ver)
			if XLIST[now] == 1:
				break
		print('A', now, flush=True)
		if int(input()) in Y:
			print('C', now, flush=True)
		else:
			print('C', -1, flush=True)


from collections import deque
import sys
t = int(input())
for i in range(t):
	n = int(input())
	edge = {}
	for j in range(1, n + 1):
		a = set()
		edge[j] = a
	for k in range(n - 1):
		(a, b) = map(int, input().split())
		edge[a].add(b)
		edge[b].add(a)
	k1 = int(input())
	x = input().split()
	mysubg = set()
	for j in range(len(x)):
		mysubg.add(int(x[j]))
	k2 = int(input())
	y = input().split()
	notmysubg = set()
	for j in range(len(y)):
		notmysubg.add(int(y[j]))
	root = int(x[0])
	print('B ' + y[0])
	sys.stdout.flush()
	goal = int(input())
	d = deque([root])
	visit = set()
	parent = {}
	while len(d) > 0:
		cur = d.popleft()
		for neigh in edge[cur]:
			if neigh not in visit:
				visit.add(neigh)
				d.append(neigh)
				parent[neigh] = cur
	while goal != root:
		if goal in mysubg:
			break
		goal = parent[goal]
	print('A ' + str(goal))
	sys.stdout.flush()
	goal2 = int(input())
	if goal2 in notmysubg:
		print('C ' + str(goal))
	else:
		print('C -1')


import sys

def ask(u, t):
	if t == 0:
		print('A', u)
	else:
		print('B', u)
	sys.stdout.flush()
	return int(input())

def solve():
	n = int(input())
	e = [[] for _ in range(n + 1)]
	p = [0] * (n + 1)
	inA = [False] * (n + 1)
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		e[u].append(v)
		e[v].append(u)

	def dfs(v):
		for u in e[v]:
			if p[u] == 0:
				p[u] = v
				dfs(u)
	a = int(input())
	A = list(map(int, input().split()))
	for u in A:
		inA[u] = True
	b = int(input())
	B = list(map(int, input().split()))
	dfs(A[0])
	r = ask(B[0], 1)
	while not inA[r]:
		r = p[r]
	v = ask(r, 0)
	print('C', r) if v in B else print('C', -1)
	sys.stdout.flush()
t = int(input())
for _ in range(t):
	solve()


import sys
from math import *
from random import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n = mint()
	e = [[] for i in range(n + 1)]
	p = [None] * (n + 1)
	my = [False] * (n + 1)
	for i in range(n - 1):
		(a, b) = mints()
		e[a].append(b)
		e[b].append(a)

	def dfs(x):
		for i in e[x]:
			if p[i] == None:
				p[i] = x
				dfs(i)
	k1 = mint()
	x = list(mints())
	for i in x:
		my[i] = True
	k2 = mint()
	y = list(mints())
	p[x[0]] = 0
	dfs(x[0])
	print('B', y[0])
	sys.stdout.flush()
	z = mint()
	while my[z] != True:
		z = p[z]
	print('A', z)
	sys.stdout.flush()
	zz = mint()
	if zz in y:
		print('C', z)
	else:
		print('C', -1)
	sys.stdout.flush()
t = mint()
for i in range(t):
	solve()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
from heapq import heappop, heappush

def dijkstra(n, graph, start):
	(dist, parents) = ([float('inf')] * n, [-1] * n)
	dist[start] = 0
	queue = [(0, start)]
	while queue:
		(path_len, v) = heappop(queue)
		if path_len == dist[v]:
			for (w, edge_len) in graph[v]:
				if edge_len + path_len < dist[w]:
					(dist[w], parents[w]) = (edge_len + path_len, v)
					heappush(queue, (edge_len + path_len, w))
	return dist
for _ in range(int(input()) if True else 1):
	n = int(input())
	graph = [[] for __ in range(n + 1)]
	for i in range(n - 1):
		(x, y) = map(int, input().split())
		graph[x] += [(y, 1)]
		graph[y] += [(x, 1)]
	k1 = int(input())
	x = list(map(int, input().split()))
	k2 = int(input())
	y = list(map(int, input().split()))
	print(f'B {y[0]}', flush=True)
	ans = int(input())
	dik = dijkstra(n + 1, graph, ans)
	minn = 999999
	ans = 0
	for i in x:
		if dik[i] < minn:
			minn = dik[i]
			ans = i
	print(f'A {ans}', flush=True)
	b = int(input())
	if b in y:
		print(f'C {ans}', flush=True)
	else:
		print('C -1', flush=True)


def add(child, path):
	copy = path[:]
	return copy + [child]

def dfs(tree, start, end, path):
	if start == end:
		return path
	for child in tree[start]:
		if child in path:
			continue
		else:
			x = dfs(tree, child, end, add(child, path))
			if x != None:
				return x
	return None
t = int(input())
for i in range(t):
	n = int(input())
	neighbors = {}
	for i in range(1, n + 1):
		neighbors[i] = []
	for i in range(n - 1):
		(a, b) = map(int, input().split())
		neighbors[a].append(b)
		neighbors[b].append(a)
	k1 = int(input())
	mine = list(map(int, input().split()))
	k2 = int(input())
	his = list(map(int, input().split()))
	print('B', his[0])
	r = int(input())
	if r in mine:
		print('C', r)
		continue
	way = dfs(neighbors, r, mine[0], [r])
	for guy in way:
		if guy in mine:
			x = guy
			print('A', guy)
			break
	s = int(input())
	if s in his:
		print('C', x)
	else:
		print('C', -1)


from collections import defaultdict
from math import log2
from bisect import bisect_left
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.setrecursionlimit(10 ** 5)

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

@bootstrap
def dfs(u, par):
	global depth
	for j in adj[u]:
		if j != par:
			depth[j] = depth[u] + 1
			yield dfs(j, u)
	yield

def query(s, val):
	print(f'{s} {val}')
	sys.stdout.flush()
	return int(input())
t = int(input())
for _ in range(t):
	n = int(input())
	adj = [[] for i in range(n + 1)]
	for i in range(n - 1):
		(u, v) = map(int, input().split())
		adj[u].append(v)
		adj[v].append(u)
	k1 = int(input())
	a = list(map(int, input().split()))
	k2 = int(input())
	b = list(map(int, input().split()))
	sys.stdout.flush()
	root = query('B', b[0])
	depth = [0 for i in range(n + 1)]
	dfs(root, 0)
	m = float('inf')
	for j in a:
		if depth[j] < m:
			m = depth[j]
			ver = j
	sys.stdout.flush()
	val = query('A', ver)
	sys.stdout.flush()
	if val in b:
		print(f'C {ver}')
	else:
		print(f'C {-1}')
	sys.stdout.flush()