#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using dbl = double;
const int N = 1010;
int n;
vector<int> go[N];
vector<int> vs1, vs2;
vector<int> readV() {
  int sz;
  cin >> sz;
  vector<int> res(sz);
  for (auto& x : res) {
    cin >> x;
    --x;
  }
  return res;
}
int ask1(int v) {
  cout << "A " << v + 1 << endl;
  int u;
  cin >> u;
  --u;
  return u;
}
int ask2(int v) {
  cout << "B " << v + 1 << endl;
  int u;
  cin >> u;
  --u;
  return u;
}
int hs[N];
void dfs(int v, int p) {
  for (auto u : go[v]) {
    if (u == p) continue;
    hs[u] = hs[v] + 1;
    dfs(u, v);
  }
}
void solve1() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    go[i].clear();
  }
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    go[a].push_back(b);
    go[b].push_back(a);
  }
  vs1 = readV();
  vs2 = readV();
  auto r = ask2(vs2[0]);
  hs[r] = 0;
  dfs(r, -1);
  int best = vs1[0];
  for (auto x : vs1)
    if (hs[x] < hs[best]) best = x;
  auto y = ask1(best);
  if (find(vs2.begin(), vs2.end(), y) == vs2.end()) {
    cout << -1 << endl;
  } else {
    cout << best + 1 << endl;
  }
}
void solve() {
  ios_base::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) solve1();
}
int main() {
  solve();
  (void)0;
}
