#include <bits/stdc++.h>
using namespace std;
vector<int> adjlist[1005];
int vis[1005];
vector<int> leafs;
int ss[1005];
void solve() {
  int n;
  map<int, int> m1, m2;
  scanf("%d", &n);
  for (int i = 1; i < n + 1; ++i) {
    adjlist[i].clear();
  }
  for (int i = 1; i < n + 1; ++i) ss[i] = 0, vis[i] = 0;
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    adjlist[x].push_back(y);
    adjlist[y].push_back(x);
  }
  memset(vis, 0, sizeof vis);
  vector<int> l1, l2;
  int k1, k2;
  scanf("%d", &k1);
  for (int i = 0; i < k1; ++i) {
    int node;
    scanf("%d", &node);
    m1[node]++;
    l1.push_back(node);
  }
  sort(l1.begin(), l1.end());
  scanf("%d", &k2);
  for (int i = 0; i < k2; ++i) {
    int node;
    scanf("%d", &node);
    m2[node]++;
    l2.push_back(node);
  }
  sort(l2.begin(), l2.end());
  int f = 0;
  if ((int)l2.size() < (int)l1.size()) f = 1, swap(l1, l2);
  for (int i = 0; i < 100; ++i) {
    random_shuffle(l1.begin(), l1.end());
  }
  if (f) {
    int flag = 0;
    for (int i = 0; i < min((int)l1.size(), 5); ++i) {
      cout << "B " << l1[i] << '\n';
      fflush(stdout);
      int x;
      cin >> x;
      if (m1[x]) {
        cout << "C " << x << '\n';
        fflush(stdout);
        return;
      }
    }
    cout << "C -1" << '\n';
    fflush(stdout);
    return;
  } else {
    int flag = 0;
    for (int i = 0; i < min((int)l1.size(), 5); ++i) {
      cout << "A " << l1[i] << '\n';
      fflush(stdout);
      int x;
      cin >> x;
      if (m2[x]) {
        cout << "C " << l1[i] << '\n';
        fflush(stdout);
        return;
      }
    }
    cout << "C -1" << '\n';
    fflush(stdout);
    return;
  }
}
signed main() {
  int t = 1;
  srand(time(NULL));
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
