#include <bits/stdc++.h>
using namespace std;
vector<string> parser(string line) {
  string tmp;
  vector<string> ret;
  line += ' ';
  int n = line.size();
  for (int i = 0; i < n; i++) {
    if (line[i] == ' ') {
      ret.push_back(tmp);
      tmp = "";
    } else {
      tmp += line[i];
    }
  }
  return ret;
}
int str_to_int(string str) {
  stringstream sstr;
  int ret;
  sstr << str;
  sstr >> ret;
  return ret;
}
chrono::steady_clock::time_point get_now() {
  return chrono::steady_clock::now();
}
double GetTimeDiff(const chrono::steady_clock::time_point& begin_t,
                   const chrono::steady_clock::time_point& end_t) {
  return ((double)chrono::duration_cast<chrono::microseconds>(end_t - begin_t)
              .count()) /
         1000.0 / 1000.0;
}
void sub_func() {
  string line;
  int n;
  getline(cin, line);
  sscanf(line.c_str(), "%d", &n);
  unordered_map<int, vector<int>> graph_dict;
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    getline(cin, line);
    sscanf(line.c_str(), "%d %d", &x, &y);
    graph_dict[x].push_back(y);
    graph_dict[y].push_back(x);
  }
  int k1, k2;
  vector<int> subtree1, subtree2;
  unordered_set<int> vset1, vset2;
  getline(cin, line);
  sscanf(line.c_str(), "%d", &k1);
  getline(cin, line);
  vector<string> vec = parser(line);
  for (auto str : vec) {
    subtree1.push_back(str_to_int(str));
  }
  getline(cin, line);
  sscanf(line.c_str(), "%d", &k2);
  getline(cin, line);
  vec = parser(line);
  for (auto str : vec) {
    subtree2.push_back(str_to_int(str));
  }
  for (auto v : subtree1) {
    vset1.insert(v);
  }
  for (auto v : subtree2) {
    vset2.insert(v);
  }
  cout << "B " << subtree2[0] << endl;
  getline(cin, line);
  int src;
  sscanf(line.c_str(), "%d", &src);
  if (vset1.find(src) != vset1.end()) {
    cout << "C " << src << endl;
    return;
  }
  vector<int> queue = {src};
  vector<bool> touched(n, false);
  int idx = 0, dest = -1;
  bool end = false;
  while (true) {
    int q = queue[idx];
    touched[q] = true;
    idx++;
    for (auto y : graph_dict[q]) {
      if (touched[y]) {
        continue;
      }
      if (vset1.find(y) != vset1.end()) {
        dest = y;
        end = true;
        break;
      }
      queue.push_back(y);
    }
    if (end) {
      break;
    }
  }
  cout << "A " << dest << endl;
  getline(cin, line);
  sscanf(line.c_str(), "%d", &src);
  if (vset2.find(src) != vset2.end()) {
    cout << "C " << dest << endl;
  } else {
    cout << "C "
         << "-1" << endl;
  }
}
void main_func() {
  string line;
  getline(cin, line);
  int t;
  sscanf(line.c_str(), "%d", &t);
  for (int i = 0; i < t; ++i) {
    sub_func();
  }
}
int main() {
  main_func();
  return 0;
}
