#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 1e3 + 10;
vector<int> v[N];
map<int, int> mc1, mc2;
int dfs(int x, int fa = 0) {
  if (mc1.count(x)) return x;
  for (auto& y : v[x]) {
    if (y == fa) continue;
    int ret = dfs(y, x);
    if (ret != 0) return ret;
  }
  return 0;
}
int main() {
  int ncase;
  cin >> ncase;
  while (ncase--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) v[i].clear();
    for (int i = 1; i < n; i++) {
      int x, y;
      cin >> x >> y;
      v[x].push_back(y);
      v[y].push_back(x);
    }
    mc1.clear();
    mc2.clear();
    int k1, k2;
    cin >> k1;
    while (k1--) {
      int x;
      cin >> x;
      mc1[x] = 1;
    }
    cin >> k2;
    while (k2--) {
      int x;
      cin >> x;
      mc2[x] = 1;
    }
    int vb1 = mc2.begin()->first;
    int va1;
    cout << "B " << vb1 << endl;
    cin >> va1;
    int va2 = dfs(va1);
    cout << "A " << va2 << endl;
    int vb2;
    cin >> vb2;
    if (mc2.count(vb2))
      cout << "C " << va2 << endl;
    else
      cout << "C -1" << endl;
  }
  return 0;
}
