//STARTCOPY
#include<bits/stdc++.h>
using namespace std;

using u_counter_type = unsigned int;
using need_int = int;
using counter_type = int;
using MAIN = int;
#define int DontUseIntÉ
using ll = long long;

template<typename T>
using PairOf = pair<T,T>;

using Void = tuple<>;

struct BasicInitialization{
    BasicInitialization(){
        ios_base::sync_with_stdio(false);
    }
};
BasicInitialization __basic_initialization__;
namespace mytl{

template<typename T, typename R>
vector<R> fmap(R(*f)(const T), const vector<T>& t){
    vector<R> res;
    for(auto elem : t) res.push_back(f(elem));
    return res;
}

template<typename T>
vector<T> forrange(T n, T from){
    vector<T> res(n);
    iota(res.begin(), res.end(), from);
    return res;
}

template<typename F>
void repeat(need_int n, const F& callback){
    for(need_int _ : forrange(n,0)) callback();
}

template<typename T>
struct optional{
    private:
        T *val = nullptr;
        void reserve(){
            val = new T;
        }
    public:
        optional<T> operator=(const T& operand){
            reserve();
            *val = operand;
            return *this;
        }
        bool has_value(){
            return val != nullptr;
        }
        T& value(){
            return *val;
        }
        optional(T val_){
            operator=(val_);
        }
        optional(initializer_list<T> l){
            assert(l.size() == 1);
            operator=(*l.begin());
        }
        optional(){}
};

template<typename T>
optional<T> make_optional(T val_){
    return optional<T>(val_);
}

template<typename T, T(*f)(T,T)>
struct Tracker : optional<T>{
    using optional<T>::operator=;

    Tracker() : optional<T>() {};

    void update(T val){
        if(this->has_value()){
            *this = f(this->value(), val);
        }
        else{
            *this = val;
        }
    }
};

template<typename T>
T min(T a, T b){return std::min(a,b);}
template<typename T>
T max(T a, T b){return std::max(a,b);}
template<typename T>
T __gcd(T a, T b){return std::__gcd(a,b);}

template<typename T, template<typename, typename...> typename Container>
vector<PairOf<T&> > adjecent_pairs(Container<T>& c){
    vector<PairOf<T&> > res;
    optional<T*> prev_elem;
    for(auto& elem : c){
        if(prev_elem.has_value()){
            res.push_back({*prev_elem.value(), elem});
        }
        prev_elem = &elem;
    }
    return res;
}

template<typename T>
struct LazyVector : vector<T>{
    typename vector<T>::reference operator[](counter_type i){
        if(i >= this->size()) this->resize(i+1);
        return vector<T>::operator[](i);
    }
};

template<typename K, typename T>
struct AssocVector : LazyVector<T>{
    LazyVector<bool> exists;
    typename vector<T>::reference operator[](counter_type i){
        exists[i] = true;
        return LazyVector<T>::operator[](i);
    }
    typename vector<T>::iterator find(counter_type i){
        if(!exists[i]) return this->end();
        else return this->begin() + i;
    }
};

template<template<typename, typename, typename...> typename Container, typename Key, typename Value>
bool has_key(Container<Key, Value>& container, Key key){
    return container.find(key) != container.end();
}

template<typename T>
struct Lazy : optional<T>{

    function<T()> f;

    Lazy(function<T()> f) : f{f}, optional<T>() {};

    T& value(){
        if(!this->has_value()){
            optional<T>::operator=(f());
        }
        return optional<T>::value();
    }

};

#define LAZY(val, tipe) mytl::Lazy<tipe>([&](){return (val);})
#define WATCH(x) cout << (#x) << " is " << (x) << endl
}

namespace std{

template<typename T>
istream& operator>>(istream& is, mytl::optional<T>& x){
    if(!x.has_value()){
        T x_;
        is>>x_;
        x = x_;
    }
    return is;
}

istream& operator>>(istream& is, Void& x){
    return is;
}

template<typename P, typename Q>
ostream& operator<<(ostream& os, const pair<P,Q>& x){
    os<<"("<<x.first<<", "<<x.second<<")";
    return os;
}

template<typename T, template<typename, typename...> typename Container>
ostream& operator<<(ostream& os, const Container<T>& x){
    os<<"{";
    bool first = true;
    for(const auto& elem : x){
        if(!first) os<<", ";
        os<<elem;
        first = false;
    }
    os<<"}";
    return os;
}

}

namespace mytl{

template<typename T, typename P=T>
T read(istream& is=cin){
    P a;
    is>>a;
    return T(a);
}

template<typename T, typename P, typename Q>
T read(istream& is=cin){
    P a;
    Q b;
    is>>a>>b;
    return T(a,b);
}

template<typename T, typename P, typename Q, typename R>
T read(istream& is=cin){
    P a;
    Q b;
    R c;
    is>>a>>b>>c;
    return T(a,b,c);
}

template<typename T, typename... Q>
vector<T> readValues(ll n, istream& is=cin){
    vector<T> res;
    repeat(n, [&res](){
        res.push_back(read<T,Q...>());
    });
    return res;
}

}

namespace mytl{

template<typename T>
void print(const T& x, ostream& os=cout){
    os<<x;
}

}
namespace mytl{
template<typename T>
T power(T base, ll exponential, T unit=1){
    T res = unit;
    while(exponential > 0){
        if(exponential%2 == 1) res = res * base;
        base = base * base;
        exponential = exponential / 2;
    }
    return res;
}
}
namespace mytl{
    template<ll MOD>
    struct TSModulo{
    private:
        ll val;

    public:
        static TSModulo inverse(TSModulo x){// asserting MOD is prime
            return power(x, MOD-2);
        };
        TSModulo(ll initVal) : val{(MOD + initVal%MOD)%MOD} {};
        TSModulo() : TSModulo(0) {}
        TSModulo& operator=(const TSModulo&) = default;

        ll get() const{ // no type cast operator to prevent accidentally turning into ordinary number
            return val;
        }

        //Unary operators
        TSModulo operator-() const{
            return TSModulo(-val);
        };
        TSModulo operator+() const{
            return TSModulo(+val);
        };

        //Binary operators on ordinary numbers
        TSModulo operator-(const ll& operand) const{
            return TSModulo(val-operand);
        };
        TSModulo operator+(const ll& operand) const{
            return TSModulo(val+operand);
        };
        TSModulo operator*(const ll& operand) const{
            return TSModulo(val*operand);
        };
        TSModulo operator/(const ll& operand) const{ //asserting MOD is prime
            return TSModulo(inverse(operand) * val);
        };

        //Binary operators on Modulo
        TSModulo operator-(const TSModulo& operand) const{
            return TSModulo(val-operand.get());
        };
        TSModulo operator+(const TSModulo& operand) const{
            return TSModulo(val+operand.get());
        };
        TSModulo operator*(const TSModulo& operand) const{
            return TSModulo(val*operand.get());
        };
        TSModulo operator/(const TSModulo& operand) const{ //asserting MOD is prime
            return TSModulo(val * inverse(operand));
        };
    };

    using Mod107 = TSModulo<1000000007LL>;

    template<ll MOD>
    ostream& operator<<(ostream& os, TSModulo<MOD> x){
        return os<<"("<<x.get()<<"%"<<MOD<<")";
    }

}
namespace mytl{
    struct Modulo{
        static ll global_mod;
    private:
        ll val;
    public:
        const ll MOD;
        Modulo(ll initMOD, ll initVal) : MOD{initMOD}, val{initVal} {
            val %= MOD;
            if(val < 0) val += MOD;
        };
        Modulo() : Modulo(global_mod, 0) {};

        static Modulo inverse(Modulo x){// asserting MOD is prime
            return power(x, x.MOD-2, x.unit());
        };
        Modulo unit() const{
            return Modulo(MOD, 1);
        }
        Modulo& operator=(const Modulo& operand){
            val = operand.val;
            return *this;
        };

        ll get() const{ // no type cast operator to prevent accidentally turning into ordinary number
            return val;
        }

        //Unary operators
        Modulo operator-() const{
            return Modulo(MOD, -val);
        };
        Modulo operator+() const{
            return Modulo(MOD, +val);
        };

        //Binary operators on ordinary numbers
        Modulo operator-(const ll& operand) const{
            return Modulo(MOD, val-operand);
        };
        Modulo operator+(const ll& operand) const{
            return Modulo(MOD, val+operand);
        };
        Modulo operator*(const ll& operand) const{
            return Modulo(MOD, val*operand);
        };
        Modulo operator/(const ll& operand) const{ //asserting MOD is prime
            return Modulo(MOD, val * inverse(Modulo(MOD, operand)).get());
        };

        //Binary operators on Modulo
        Modulo operator-(const Modulo& operand) const{
            return Modulo(MOD, val-operand.get());
        };
        Modulo operator+(const Modulo& operand) const{
            return Modulo(MOD, val+operand.get());
        };
        Modulo operator*(const Modulo& operand) const{
            return Modulo(MOD, val*operand.get());
        };
        Modulo operator/(const Modulo& operand) const{ //asserting MOD is prime
            return Modulo(MOD, val * inverse(operand).get());
        };

    };

    ll Modulo::global_mod = 1000000007LL;

    Modulo mod107(ll x){
        return Modulo(1000000007LL, x);
    }
    ostream& operator<<(ostream& os, Modulo x){
        return os<<"("<<x.get()<<"%"<<x.MOD<<")";
    }

}
namespace mytl {

template<class T>
struct Resetter;

template<class T>
Resetter<T>* global_resetter = new Resetter<T>;

template<class T>
struct Resetter {

    using State = pair<counter_type, T>;

    State* state = new State{0, T()};

    Resetter(){}
    Resetter(T value){
        state = new State{0, value};
    }

    void activate(){
        global_resetter<T> = this;
    }

    void reset(T value){
        *state = State{state->first+1, value};
    }

    struct Variable{

        State state;
        State& parent = *global_resetter<T>->state;

        Variable() : state{*global_resetter<T>->state} {}
        Variable(T value) : state{global_resetter<T>->state->first, value} {}
        Variable(State st) : state{st} {}
        Variable(T value, State& parent) : state{parent->first, value} {};

        bool fresh(){
            return state.first >= parent.first;
        }

        void overwrite(){
            state = parent;
        }

        bool refresh(){
            if(!fresh()) overwrite();
        }

        T get(){
            refresh();
            return state.second;
        }

        void survive(){
            state.first = parent.first;
        }

        void operator=(T new_value){
            state.second = new_value;
            survive();
        }

    };

};
}
namespace mytl{

template<typename N, typename E, template<typename, typename, typename...> typename C>
struct Container_Graph : C<N, vector<pair<E, N> > >{
    template<typename A, typename B>
    using Container = C<A,B>;
    using Edge = E;
    using Node = N;
    optional<ll> n;
    Container_Graph(ll n={}) : n{n}, Container<Node, vector<pair<Edge, Node> > >() {}

    void newEdge(Node u, Node v, Edge edge=Void()){
        (*this)[u].push_back(make_pair(edge, v));
    }
    vector<Node> getNodes(){
        vector<Node> res;
        if(n.has_value()){
            for(ll i=1; i<=n.value(); i++) res.push_back(i);
        }
        else{
            for(auto& p : *this){
                res.push_back(p.first);
            }
        }
        return res;

    }
    vector<pair<Edge, Node> >& getEdges(Node node){
        return (*this)[node];
    }
    vector<Node > getNeighbours(Node node){
        vector<Node> res;
        for(auto& par : getEdges(node)){
            res.push_back(par.second);
        }
        return res;
    }

};

using NormalSimpleGraph = Container_Graph<ll, Void, AssocVector>;

template<typename G>
void readNeighbourList(G& g, ll indexing=1){
    for(ll i : forrange(g.n.size(), indexing)){
        for(ll neig : readValues<ll>(read<ll>())){
            g.new_edge(i, neig);
        }
    }
}

template<typename G>
void readEdgeList(G& g, ll m, bool bidirectional=true){
    using Node = typename G::Node;
    using Edge = typename G::Edge;
    for(auto elem : readValues<tuple<Node, Node, Edge>, Node, Node, Edge >(m)){
        Node u, v;
        Edge edge;
        tie(u, v, edge) = elem;
        g.newEdge(u,v,edge);
        if(bidirectional) g.newEdge(v, u, edge);
    }
}

template<
    typename G,
    template<typename> typename A,
    typename F=void(*)(typename A<G>::Option)
>
typename G::template Container<typename G::Node, typename A<G>::Info> queue_graph_algorithm(
    G& g,
    vector<typename A<G>::Option > sources,
    F new_node_callback=[](typename A<G>::Option){})
{
    using Algo = A<G>;
    typename Algo::Queue q;

    for(auto source : sources) q.push(source);
    typename G::template Container<typename G::Node, typename Algo::Info> d;
    while(!q.empty()){
        auto akt = Algo::consume(q);
        typename Algo::Node who = akt.second;
        typename Algo::Info info = akt.first;

        if(has_key(d, who)) continue;

        d[who] = info;

        new_node_callback({info, who});
        for(auto par : g.getEdges(who)) if(!has_key(d, par.second)){
            q.push({Algo::append({info, who}, par.first, par.second), par.second});
        }
    }
    return d;
}

template<template<typename> typename QP, template<typename> typename P>
struct AlgoComposer{
    template<typename G>
    struct A{
        using Path = P<G>;
        using Edge = typename G::Edge;
        using Node = typename G::Node;
        using Info = typename Path::Info;
        using Option = pair<Info, Node>;
        using QueuePolicy = QP<Option>;
        using Queue = typename QueuePolicy::Queue;

        static Option consume(Queue& q){
            return QueuePolicy::consume(q);
        }
        static void push(Queue& q, Option new_option){
            return QueuePolicy::push(q, new_option);
        }
        static Info append(pair<Info, Node> from , Edge e, Node to){
            return Path::append(from, e, to);
        }
    };
};

template<typename T>
struct Priority{
    using Queue = priority_queue<T, vector<T>, greater<T> >;
    static T consume(Queue& q){
        auto res = q.top();
        q.pop();
        return res;
    }
    static void push(Queue& q, T new_option){
        q.push(new_option);
    }
};

template<typename T>
struct FIFO{
    using Queue = queue<T>;
    static T consume(Queue& q){
        auto res = q.front();
        q.pop();
        return res;
    }
    static void push(Queue& q, T new_option){
        q.push(new_option);
    }
};

template<typename T>
struct FILO{
    using Queue = stack<T>;
    static T consume(Queue& q){
        auto res = q.top();
        q.pop();
        return res;
    }
    static void push(Queue& q, T new_option){
        q.pop();
    }
};

template<typename G>
struct JustLength{
    using Info = typename G::Edge;
    static Info append(pair<Info, typename G::Node> from, typename G::Edge e, typename G::Node n){
        return from.first + e;
    }
};

template<typename G>
struct SimpleJustLength{
    using Info = ll;
    static Info append(pair<Info, typename G::Node> from, typename G::Edge e, typename G::Node n){
        return from.first + 1;
    }
};

template<typename G>
struct LengthAndLastNode{
    using Info = pair<ll, typename G::Node>;
    static Info append(pair<Info, typename G::Node> from, typename G::Edge e, typename G::Node n){
        return Info(from.first + e, from.second);
    }
};

template<typename G>
struct SimpleLengthAndLastNode{
    using Info = pair<ll, typename G::Node>;
    static Info append(pair<Info, typename G::Node> from, typename G::Edge e, typename G::Node n){
        return Info(from.first.first + 1, from.second);
    }
};

/*
template<typename G>
struct Custom{
    using Edge = typename G::Edge;
    using Node = typename G::Node;

    using Info = _;
    using Option = pair<Info, Edge>;
    using Queue = _;

    static Option consume(Queue &q){
        _
        return _;
    }

    static void push(Queue &q, Option new_option){
        _
    }

    static Info append(Option from, Edge e, Node to){
        return _
    }

};
*/
}
namespace mytl{

struct Point{
    ll x, y;

    Point(ll x, ll y) : x{x}, y{y} {};
    Point(pair<ll,ll> initPair) : x{initPair.first}, y{initPair.second} {};

    pair<ll,ll> getPair(){//not introducing type cast operator for safety
        return {x,y};
    }

    //Unary operators
    Point operator-() const{
        return {-x, -y};
    }
    Point operator+() const{
        return {x,y};
    }

    static ll sgn(ll x){
        return (x > 0) - (x < 0);
    }

    //Binary operators on ordinary numbers
    Point operator*(const ll& operand) const{
        return {x*operand, y*operand};
    }

    //Binary operators on Point itself
    Point operator+(const Point& operand) const{
        return {x+operand.x, y+operand.y};
    }
    Point operator-(const Point& operand) const{
        return {x-operand.x, y-operand.y};
    }

    ll operator*(const Point& operand){ //vectorial product
        return x*operand.y - y*operand.x;
    }

    ll direction(const Point& a, const Point& b) const{
        return sgn((a - *this) * (b - *this));
    };
};

ll distance_squared(const Point& a, const Point& b){
    return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);
}

double distance(const Point& a, const Point& b){
    return sqrt(distance_squared(a, b));
}

ll cartesian_distance(const Point& a, const Point& b){
    return abs(a.x - b.x) + abs(a.y - b.y);
}

typedef vector<Point> Poly;

bool inside(const Poly& poly, const Point& point, bool strict){ //assuming Poly is weakly convex
    ll prevdir = -2;
    for(ll i=0; i<poly.size(); i++){
        ll nexdindex = (i+1)%poly.size();
        ll dir = poly[i].direction(poly[nexdindex], point);
        if(dir == 0){
            if(strict) return false;
        }
        else{
            if(dir != prevdir && prevdir != -2) return false;
            prevdir = dir;
        }

    }
    return true;
}

}
namespace mytl{
template<class Op>
struct Node : Op::Range{
    using Range = typename Op::Range;
    using T = typename Op::T;
    using Change = typename Op::Change;
    using Range::singleton;
    using Range::inside;
    using Range::intersect;
    using Range::leftHalf;
    using Range::rightHalf;

    Node *left_child=NULL, *right_child=NULL;

    T partial;
    Change pending = Op::identity();

    Node(Range range) : Range(range), partial{Op::initial(range)} {};

    T query(Range range, Change change){
        return query_(range, change).first;
    }

    void add(Change change){
        pending = Op::push(pending, change);
    }

    void prepare(){
        if(!singleton()){
            if(left_child == NULL) left_child = (new Node(leftHalf()));
            if(right_child == NULL) right_child = (new Node(rightHalf()));
            left_child->add(pending);
            right_child->add(pending);
        }
        partial = Op::apply(*this, partial, pending);
        pending = Op::identity();
    }

    pair<T,T> query_(Range range, Change change){
        //cout<<range<<" "<<*this<<endl;
        prepare();
        if(inside(range)){
            add(change);
            prepare();
            return {partial, Op::zero()};
        }
        if(!intersect(range)){
            //cout<<"n"<<range<<" "<<*this<<endl;
            return {Op::zero(), partial};
        }

        auto from_left = left_child->query_(range, change);
        auto from_right = right_child->query_(range, change);
        //cout<<from_right.first<<endl;
        auto needed = Op::reduce(from_left.first, from_right.first), rest = Op::reduce(from_left.second, from_right.second);
        partial = Op::reduce(needed, rest);
        return {needed, rest};
    }

    T build_from(const function<T(ll)>& getter){
        prepare();
        pending = Op::identity();
        if(singleton()) partial = getter(this->first);
        else partial = Op::reduce(left_child->build_from(getter), right_child->build_from(getter));
        return partial;
    }

};

struct Range1D : PairOf<ll>{
    using PairOf<ll>::pair;

    ll span() const {
        return second-first+1;
    }
    bool singleton() const {
        return span() == 1;
    }
    Range1D leftHalf() const {
        return Range1D(first, (first+second)/2);
    }
    Range1D rightHalf() const {
        return Range1D((first + second)/2 + 1, second);
    }
    bool inside(const Range1D& other) const {
        return other.first <= first && second <= other.second;
    }
    bool intersect(const Range1D& other) const {

        return other.inside(*this)
             ||(other.first <= first && first <= other.second)
             ||(other.first <= second && second <= other.second);
    }
};

}

namespace mytl{
template<typename T_>
struct Add_Sum{
    using Range = Range1D;
    using T = T_;
    using Change = T_;

    static Change identity(){
        return 0;
    }

    static T zero(){
        return 0;
    }

    static T initial(Range r){
        return zero();
    }

    static T reduce(T a, T b){
        return a + b;
    }

    static T apply(Range r, T a, Change c){
        return a + r.span()*c;
    }

    static Change push(Change a, Change b){
        return a + b;
    }
};

template<typename T_>
struct Multiply_Sum{
    using Range = Range1D;
    using T = T_;
    using Change = T_;

    static Change identity(){
        return 1;
    }

    static T zero(){
        return 0;
    }

    static T initial(Range r){
        return r.span()*1;
    }

    static T reduce(T a, T b){
        return a + b;
    }

    static T apply(Range r, T a, Change c){
        return a*c;
    }

    static Change push(Change a, Change b){
        return a*b;
    }
};

}

namespace mytl{
/*
struct Custom_Op{
    using Range = _;
    using T = _;
    using Change = _;

    static Change identity(){
        return _;
    }

    static T zero(){
        return _;
    }

    static T initial(Range r){
        return _;
    }

    static T reduce(T a, T b){
        return _;
    }

    static T apply(Range r, T a, Change c){
        return _;
    }

    static Change push(Change a, Change b){
        return _;
    }

};
*/

}
namespace mytl{

template <template<typename, typename, typename...> typename C, typename Arg, typename R>
function<R (Arg)> memoize(R (*fn)(Arg)) {
    C<Arg, optional<R> > table;
    return [fn, table](Arg arg) mutable -> R {
        optional<R>& res = table[arg];
        if(!res.has_value()){
            res = fn(arg);
        }
        return res.value();
    };
}

}
//ENDCOPY

using G = mytl::Container_Graph<ll, Void, mytl::AssocVector>;

void processs(){
    ll n;
    cin>>n;
    G g(n);
    mytl::readEdgeList(g, n-1);

        cout<<"hh";
    auto enyem_ = mytl::readValues<ll>(mytl::read<ll>());
    set<ll> enyem(enyem_.begin(), enyem_.end());
    auto ove_ = mytl::readValues<ll>(mytl::read<ll>());
    set<ll> ove(ove_.begin(), ove_.end());

    cout<<enyem<<" "<<ove<<endl;
    auto ask = [&](ll& ide, char tipus, ll ki) -> bool{
        cout<<tipus<<" "<<ki<<endl;
        ll got;
        cin>>got;
        if(tipus == 'A' && mytl::has_key(ove, got)){
            cout<<"C "<<ki<<endl;
            return true;
        }
        if(tipus == 'B' && mytl::has_key(enyem, got)){
            cout<<"C "<<got<<endl;
            return true;
        }
        ide = got;
        return false;

    };

    ll one_piece;
    if(ask(one_piece, 'B', *ove.begin())) return;
     vector<pair<pair<ll,ll>, ll> > sour{{{0,-1}, *enyem.begin()}};
     cout<<sour<<endl;
    auto tb = mytl::queue_graph_algorithm<G, mytl::AlgoComposer<mytl::FILO,mytl::SimpleLengthAndLastNode>::A >(g,sour);

    while(!mytl::has_key(enyem, one_piece)){
        one_piece = tb[one_piece].second;
    }

    ll dc;
    if(ask(dc, 'A', one_piece)) return;
    else{
        cout<<"C -1"<<endl;
    }

}

MAIN main(){
    ll T;
    cin>>T;
    mytl::repeat(T, [&](){
        processs();
    }) ;
}


//STARTCOPY
#include<bits/stdc++.h>
using namespace std;

using u_counter_type = unsigned int;
using need_int = int;
using counter_type = int;
using MAIN = int;
#define int DontUseIntÉ
using ll = long long;

template<typename T>
using PairOf = pair<T,T>;

using Void = tuple<>;

struct BasicInitialization{
    BasicInitialization(){
        ios_base::sync_with_stdio(false);
    }
};
BasicInitialization __basic_initialization__;
namespace mytl{

template<typename T, typename R>
vector<R> fmap(R(*f)(const T), const vector<T>& t){
    vector<R> res;
    for(auto elem : t) res.push_back(f(elem));
    return res;
}

template<typename T>
vector<T> forrange(T n, T from){
    vector<T> res(n);
    iota(res.begin(), res.end(), from);
    return res;
}

template<typename F>
void repeat(need_int n, const F& callback){
    for(need_int _ : forrange(n,0)) callback();
}

template<typename T>
struct optional{
    private:
        T *val = nullptr;
        void reserve(){
            val = new T;
        }
    public:
        optional<T> operator=(const T& operand){
            reserve();
            *val = operand;
            return *this;
        }
        bool has_value(){
            return val != nullptr;
        }
        T& value(){
            return *val;
        }
        optional(T val_){
            operator=(val_);
        }
        optional(initializer_list<T> l){
            assert(l.size() == 1);
            operator=(*l.begin());
        }
        optional(){}
};

template<typename T>
optional<T> make_optional(T val_){
    return optional<T>(val_);
}

template<typename T, T(*f)(T,T)>
struct Tracker : optional<T>{
    using optional<T>::operator=;

    Tracker() : optional<T>() {};

    void update(T val){
        if(this->has_value()){
            *this = f(this->value(), val);
        }
        else{
            *this = val;
        }
    }
};

template<typename T>
T min(T a, T b){return std::min(a,b);}
template<typename T>
T max(T a, T b){return std::max(a,b);}
template<typename T>
T __gcd(T a, T b){return std::__gcd(a,b);}

template<typename T, template<typename, typename...> typename Container>
vector<PairOf<T&> > adjecent_pairs(Container<T>& c){
    vector<PairOf<T&> > res;
    optional<T*> prev_elem;
    for(auto& elem : c){
        if(prev_elem.has_value()){
            res.push_back({*prev_elem.value(), elem});
        }
        prev_elem = &elem;
    }
    return res;
}

template<typename T>
struct LazyVector : vector<T>{
    typename vector<T>::reference operator[](counter_type i){
        if(i >= this->size()) this->resize(i+1);
        return vector<T>::operator[](i);
    }
};

template<typename K, typename T>
struct AssocVector : LazyVector<T>{
    LazyVector<bool> exists;
    typename vector<T>::reference operator[](counter_type i){
        exists[i] = true;
        return LazyVector<T>::operator[](i);
    }
    typename vector<T>::iterator find(counter_type i){
        if(!exists[i]) return this->end();
        else return this->begin() + i;
    }
};

template<template<typename, typename, typename...> typename Container, typename Key, typename Value>
bool has_key(Container<Key, Value>& container, Key key){
    return container.find(key) != container.end();
}

template<typename T>
struct Lazy : optional<T>{

    function<T()> f;

    Lazy(function<T()> f) : f{f}, optional<T>() {};

    T& value(){
        if(!this->has_value()){
            optional<T>::operator=(f());
        }
        return optional<T>::value();
    }

};

#define LAZY(val, tipe) mytl::Lazy<tipe>([&](){return (val);})
#define WATCH(x) cout << (#x) << " is " << (x) << endl
}

namespace std{

template<typename T>
istream& operator>>(istream& is, mytl::optional<T>& x){
    if(!x.has_value()){
        T x_;
        is>>x_;
        x = x_;
    }
    return is;
}

istream& operator>>(istream& is, Void& x){
    return is;
}

template<typename P, typename Q>
ostream& operator<<(ostream& os, const pair<P,Q>& x){
    os<<"("<<x.first<<", "<<x.second<<")";
    return os;
}

template<typename T, template<typename, typename...> typename Container>
ostream& operator<<(ostream& os, const Container<T>& x){
    os<<"{";
    bool first = true;
    for(const auto& elem : x){
        if(!first) os<<", ";
        os<<elem;
        first = false;
    }
    os<<"}";
    return os;
}

}

namespace mytl{

template<typename T, typename P=T>
T read(istream& is=cin){
    P a;
    is>>a;
    return T(a);
}

template<typename T, typename P, typename Q>
T read(istream& is=cin){
    P a;
    Q b;
    is>>a>>b;
    return T(a,b);
}

template<typename T, typename P, typename Q, typename R>
T read(istream& is=cin){
    P a;
    Q b;
    R c;
    is>>a>>b>>c;
    return T(a,b,c);
}

template<typename T, typename... Q>
vector<T> readValues(ll n, istream& is=cin){
    vector<T> res;
    repeat(n, [&res](){
        res.push_back(read<T,Q...>());
    });
    return res;
}

}

namespace mytl{

template<typename T>
void print(const T& x, ostream& os=cout){
    os<<x;
}

}
namespace mytl{
template<typename T>
T power(T base, ll exponential, T unit=1){
    T res = unit;
    while(exponential > 0){
        if(exponential%2 == 1) res = res * base;
        base = base * base;
        exponential = exponential / 2;
    }
    return res;
}
}
namespace mytl{
    template<ll MOD>
    struct TSModulo{
    private:
        ll val;

    public:
        static TSModulo inverse(TSModulo x){// asserting MOD is prime
            return power(x, MOD-2);
        };
        TSModulo(ll initVal) : val{(MOD + initVal%MOD)%MOD} {};
        TSModulo() : TSModulo(0) {}
        TSModulo& operator=(const TSModulo&) = default;

        ll get() const{ // no type cast operator to prevent accidentally turning into ordinary number
            return val;
        }

        //Unary operators
        TSModulo operator-() const{
            return TSModulo(-val);
        };
        TSModulo operator+() const{
            return TSModulo(+val);
        };

        //Binary operators on ordinary numbers
        TSModulo operator-(const ll& operand) const{
            return TSModulo(val-operand);
        };
        TSModulo operator+(const ll& operand) const{
            return TSModulo(val+operand);
        };
        TSModulo operator*(const ll& operand) const{
            return TSModulo(val*operand);
        };
        TSModulo operator/(const ll& operand) const{ //asserting MOD is prime
            return TSModulo(inverse(operand) * val);
        };

        //Binary operators on Modulo
        TSModulo operator-(const TSModulo& operand) const{
            return TSModulo(val-operand.get());
        };
        TSModulo operator+(const TSModulo& operand) const{
            return TSModulo(val+operand.get());
        };
        TSModulo operator*(const TSModulo& operand) const{
            return TSModulo(val*operand.get());
        };
        TSModulo operator/(const TSModulo& operand) const{ //asserting MOD is prime
            return TSModulo(val * inverse(operand));
        };
    };

    using Mod107 = TSModulo<1000000007LL>;

    template<ll MOD>
    ostream& operator<<(ostream& os, TSModulo<MOD> x){
        return os<<"("<<x.get()<<"%"<<MOD<<")";
    }

}
namespace mytl{
    struct Modulo{
        static ll global_mod;
    private:
        ll val;
    public:
        const ll MOD;
        Modulo(ll initMOD, ll initVal) : MOD{initMOD}, val{initVal} {
            val %= MOD;
            if(val < 0) val += MOD;
        };
        Modulo() : Modulo(global_mod, 0) {};

        static Modulo inverse(Modulo x){// asserting MOD is prime
            return power(x, x.MOD-2, x.unit());
        };
        Modulo unit() const{
            return Modulo(MOD, 1);
        }
        Modulo& operator=(const Modulo& operand){
            val = operand.val;
            return *this;
        };

        ll get() const{ // no type cast operator to prevent accidentally turning into ordinary number
            return val;
        }

        //Unary operators
        Modulo operator-() const{
            return Modulo(MOD, -val);
        };
        Modulo operator+() const{
            return Modulo(MOD, +val);
        };

        //Binary operators on ordinary numbers
        Modulo operator-(const ll& operand) const{
            return Modulo(MOD, val-operand);
        };
        Modulo operator+(const ll& operand) const{
            return Modulo(MOD, val+operand);
        };
        Modulo operator*(const ll& operand) const{
            return Modulo(MOD, val*operand);
        };
        Modulo operator/(const ll& operand) const{ //asserting MOD is prime
            return Modulo(MOD, val * inverse(Modulo(MOD, operand)).get());
        };

        //Binary operators on Modulo
        Modulo operator-(const Modulo& operand) const{
            return Modulo(MOD, val-operand.get());
        };
        Modulo operator+(const Modulo& operand) const{
            return Modulo(MOD, val+operand.get());
        };
        Modulo operator*(const Modulo& operand) const{
            return Modulo(MOD, val*operand.get());
        };
        Modulo operator/(const Modulo& operand) const{ //asserting MOD is prime
            return Modulo(MOD, val * inverse(operand).get());
        };

    };

    ll Modulo::global_mod = 1000000007LL;

    Modulo mod107(ll x){
        return Modulo(1000000007LL, x);
    }
    ostream& operator<<(ostream& os, Modulo x){
        return os<<"("<<x.get()<<"%"<<x.MOD<<")";
    }

}
namespace mytl {

template<class T>
struct Resetter;

template<class T>
Resetter<T>* global_resetter = new Resetter<T>;

template<class T>
struct Resetter {

    using State = pair<counter_type, T>;

    State* state = new State{0, T()};

    Resetter(){}
    Resetter(T value){
        state = new State{0, value};
    }

    void activate(){
        global_resetter<T> = this;
    }

    void reset(T value){
        *state = State{state->first+1, value};
    }

    struct Variable{

        State state;
        State& parent = *global_resetter<T>->state;

        Variable() : state{*global_resetter<T>->state} {}
        Variable(T value) : state{global_resetter<T>->state->first, value} {}
        Variable(State st) : state{st} {}
        Variable(T value, State& parent) : state{parent->first, value} {};

        bool fresh(){
            return state.first >= parent.first;
        }

        void overwrite(){
            state = parent;
        }

        bool refresh(){
            if(!fresh()) overwrite();
        }

        T get(){
            refresh();
            return state.second;
        }

        void survive(){
            state.first = parent.first;
        }

        void operator=(T new_value){
            state.second = new_value;
            survive();
        }

    };

};
}
namespace mytl{

template<typename N, typename E, template<typename, typename, typename...> typename C>
struct Container_Graph : C<N, vector<pair<E, N> > >{
    template<typename A, typename B>
    using Container = C<A,B>;
    using Edge = E;
    using Node = N;
    optional<ll> n;
    Container_Graph(ll n={}) : n{n}, Container<Node, vector<pair<Edge, Node> > >() {}

    void newEdge(Node u, Node v, Edge edge=Void()){
        (*this)[u].push_back(make_pair(edge, v));
    }
    vector<Node> getNodes(){
        vector<Node> res;
        if(n.has_value()){
            for(ll i=1; i<=n.value(); i++) res.push_back(i);
        }
        else{
            for(auto& p : *this){
                res.push_back(p.first);
            }
        }
        return res;

    }
    vector<pair<Edge, Node> >& getEdges(Node node){
        return (*this)[node];
    }
    vector<Node > getNeighbours(Node node){
        vector<Node> res;
        for(auto& par : getEdges(node)){
            res.push_back(par.second);
        }
        return res;
    }

};

using NormalSimpleGraph = Container_Graph<ll, Void, AssocVector>;

template<typename G>
void readNeighbourList(G& g, ll indexing=1){
    for(ll i : forrange(g.n.size(), indexing)){
        for(ll neig : readValues<ll>(read<ll>())){
            g.new_edge(i, neig);
        }
    }
}

template<typename G>
void readEdgeList(G& g, ll m, bool bidirectional=true){
    using Node = typename G::Node;
    using Edge = typename G::Edge;
    for(auto elem : readValues<tuple<Node, Node, Edge>, Node, Node, Edge >(m)){
        Node u, v;
        Edge edge;
        tie(u, v, edge) = elem;
        g.newEdge(u,v,edge);
        if(bidirectional) g.newEdge(v, u, edge);
    }
}

template<
    typename G,
    template<typename> typename A,
    typename F=void(*)(typename A<G>::Option)
>
typename G::template Container<typename G::Node, typename A<G>::Info> queue_graph_algorithm(
    G& g,
    vector<typename A<G>::Option > sources,
    F new_node_callback=[](typename A<G>::Option){})
{
    using Algo = A<G>;
    typename Algo::Queue q;

    for(auto source : sources) q.push(source);
    typename G::template Container<typename G::Node, typename Algo::Info> d;
    while(!q.empty()){
        auto akt = Algo::consume(q);
        typename Algo::Node who = akt.second;
        typename Algo::Info info = akt.first;

        if(has_key(d, who)) continue;

        d[who] = info;

        new_node_callback({info, who});
        for(auto par : g.getEdges(who)) if(!has_key(d, par.second)){
            q.push({Algo::append({info, who}, par.first, par.second), par.second});
        }
    }
    return d;
}

template<template<typename> typename QP, template<typename> typename P>
struct AlgoComposer{
    template<typename G>
    struct A{
        using Path = P<G>;
        using Edge = typename G::Edge;
        using Node = typename G::Node;
        using Info = typename Path::Info;
        using Option = pair<Info, Node>;
        using QueuePolicy = QP<Option>;
        using Queue = typename QueuePolicy::Queue;

        static Option consume(Queue& q){
            return QueuePolicy::consume(q);
        }
        static void push(Queue& q, Option new_option){
            return QueuePolicy::push(q, new_option);
        }
        static Info append(pair<Info, Node> from , Edge e, Node to){
            return Path::append(from, e, to);
        }
    };
};

template<typename T>
struct Priority{
    using Queue = priority_queue<T, vector<T>, greater<T> >;
    static T consume(Queue& q){
        auto res = q.top();
        q.pop();
        return res;
    }
    static void push(Queue& q, T new_option){
        q.push(new_option);
    }
};

template<typename T>
struct FIFO{
    using Queue = queue<T>;
    static T consume(Queue& q){
        auto res = q.front();
        q.pop();
        return res;
    }
    static void push(Queue& q, T new_option){
        q.push(new_option);
    }
};

template<typename T>
struct FILO{
    using Queue = stack<T>;
    static T consume(Queue& q){
        auto res = q.top();
        q.pop();
    }
    static void push(Queue& q, T new_option){
        q.pop();
    }
};

template<typename G>
struct JustLength{
    using Info = typename G::Edge;
    static Info append(pair<Info, typename G::Node> from, typename G::Edge e, typename G::Node n){
        return from.first + e;
    }
};

template<typename G>
struct SimpleJustLength{
    using Info = ll;
    static Info append(pair<Info, typename G::Node> from, typename G::Edge e, typename G::Node n){
        return from.first + 1;
    }
};

template<typename G>
struct LengthAndLastNode{
    using Info = pair<ll, typename G::Node>;
    static Info append(pair<Info, typename G::Node> from, typename G::Edge e, typename G::Node n){
        return Info(from.first + e, from.second);
    }
};

template<typename G>
struct SimpleLengthAndLastNode{
    using Info = pair<ll, typename G::Node>;
    static Info append(pair<Info, typename G::Node> from, typename G::Edge e, typename G::Node n){
        return Info(from.first.first + 1, from.second);
    }
};

/*
template<typename G>
struct Custom{
    using Edge = typename G::Edge;
    using Node = typename G::Node;

    using Info = _;
    using Option = pair<Info, Edge>;
    using Queue = _;

    static Option consume(Queue &q){
        _
        return _;
    }

    static void push(Queue &q, Option new_option){
        _
    }

    static Info append(Option from, Edge e, Node to){
        return _
    }

};
*/
}
namespace mytl{

struct Point{
    ll x, y;

    Point(ll x, ll y) : x{x}, y{y} {};
    Point(pair<ll,ll> initPair) : x{initPair.first}, y{initPair.second} {};

    pair<ll,ll> getPair(){//not introducing type cast operator for safety
        return {x,y};
    }

    //Unary operators
    Point operator-() const{
        return {-x, -y};
    }
    Point operator+() const{
        return {x,y};
    }

    static ll sgn(ll x){
        return (x > 0) - (x < 0);
    }

    //Binary operators on ordinary numbers
    Point operator*(const ll& operand) const{
        return {x*operand, y*operand};
    }

    //Binary operators on Point itself
    Point operator+(const Point& operand) const{
        return {x+operand.x, y+operand.y};
    }
    Point operator-(const Point& operand) const{
        return {x-operand.x, y-operand.y};
    }

    ll operator*(const Point& operand){ //vectorial product
        return x*operand.y - y*operand.x;
    }

    ll direction(const Point& a, const Point& b) const{
        return sgn((a - *this) * (b - *this));
    };
};

ll distance_squared(const Point& a, const Point& b){
    return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);
}

double distance(const Point& a, const Point& b){
    return sqrt(distance_squared(a, b));
}

ll cartesian_distance(const Point& a, const Point& b){
    return abs(a.x - b.x) + abs(a.y - b.y);
}

typedef vector<Point> Poly;

bool inside(const Poly& poly, const Point& point, bool strict){ //assuming Poly is weakly convex
    ll prevdir = -2;
    for(ll i=0; i<poly.size(); i++){
        ll nexdindex = (i+1)%poly.size();
        ll dir = poly[i].direction(poly[nexdindex], point);
        if(dir == 0){
            if(strict) return false;
        }
        else{
            if(dir != prevdir && prevdir != -2) return false;
            prevdir = dir;
        }

    }
    return true;
}

}
namespace mytl{
template<class Op>
struct Node : Op::Range{
    using Range = typename Op::Range;
    using T = typename Op::T;
    using Change = typename Op::Change;
    using Range::singleton;
    using Range::inside;
    using Range::intersect;
    using Range::leftHalf;
    using Range::rightHalf;

    Node *left_child=NULL, *right_child=NULL;

    T partial;
    Change pending = Op::identity();

    Node(Range range) : Range(range), partial{Op::initial(range)} {};

    T query(Range range, Change change){
        return query_(range, change).first;
    }

    void add(Change change){
        pending = Op::push(pending, change);
    }

    void prepare(){
        if(!singleton()){
            if(left_child == NULL) left_child = (new Node(leftHalf()));
            if(right_child == NULL) right_child = (new Node(rightHalf()));
            left_child->add(pending);
            right_child->add(pending);
        }
        partial = Op::apply(*this, partial, pending);
        pending = Op::identity();
    }

    pair<T,T> query_(Range range, Change change){
        //cout<<range<<" "<<*this<<endl;
        prepare();
        if(inside(range)){
            add(change);
            prepare();
            return {partial, Op::zero()};
        }
        if(!intersect(range)){
            //cout<<"n"<<range<<" "<<*this<<endl;
            return {Op::zero(), partial};
        }

        auto from_left = left_child->query_(range, change);
        auto from_right = right_child->query_(range, change);
        //cout<<from_right.first<<endl;
        auto needed = Op::reduce(from_left.first, from_right.first), rest = Op::reduce(from_left.second, from_right.second);
        partial = Op::reduce(needed, rest);
        return {needed, rest};
    }

    T build_from(const function<T(ll)>& getter){
        prepare();
        pending = Op::identity();
        if(singleton()) partial = getter(this->first);
        else partial = Op::reduce(left_child->build_from(getter), right_child->build_from(getter));
        return partial;
    }

};

struct Range1D : PairOf<ll>{
    using PairOf<ll>::pair;

    ll span() const {
        return second-first+1;
    }
    bool singleton() const {
        return span() == 1;
    }
    Range1D leftHalf() const {
        return Range1D(first, (first+second)/2);
    }
    Range1D rightHalf() const {
        return Range1D((first + second)/2 + 1, second);
    }
    bool inside(const Range1D& other) const {
        return other.first <= first && second <= other.second;
    }
    bool intersect(const Range1D& other) const {

        return other.inside(*this)
             ||(other.first <= first && first <= other.second)
             ||(other.first <= second && second <= other.second);
    }
};

}

namespace mytl{
template<typename T_>
struct Add_Sum{
    using Range = Range1D;
    using T = T_;
    using Change = T_;

    static Change identity(){
        return 0;
    }

    static T zero(){
        return 0;
    }

    static T initial(Range r){
        return zero();
    }

    static T reduce(T a, T b){
        return a + b;
    }

    static T apply(Range r, T a, Change c){
        return a + r.span()*c;
    }

    static Change push(Change a, Change b){
        return a + b;
    }
};

template<typename T_>
struct Multiply_Sum{
    using Range = Range1D;
    using T = T_;
    using Change = T_;

    static Change identity(){
        return 1;
    }

    static T zero(){
        return 0;
    }

    static T initial(Range r){
        return r.span()*1;
    }

    static T reduce(T a, T b){
        return a + b;
    }

    static T apply(Range r, T a, Change c){
        return a*c;
    }

    static Change push(Change a, Change b){
        return a*b;
    }
};

}

namespace mytl{
/*
struct Custom_Op{
    using Range = _;
    using T = _;
    using Change = _;

    static Change identity(){
        return _;
    }

    static T zero(){
        return _;
    }

    static T initial(Range r){
        return _;
    }

    static T reduce(T a, T b){
        return _;
    }

    static T apply(Range r, T a, Change c){
        return _;
    }

    static Change push(Change a, Change b){
        return _;
    }

};
*/

}
namespace mytl{

template <template<typename, typename, typename...> typename C, typename Arg, typename R>
function<R (Arg)> memoize(R (*fn)(Arg)) {
    C<Arg, optional<R> > table;
    return [fn, table](Arg arg) mutable -> R {
        optional<R>& res = table[arg];
        if(!res.has_value()){
            res = fn(arg);
        }
        return res.value();
    };
}

}
//ENDCOPY

using G = mytl::Container_Graph<ll, Void, mytl::AssocVector>;

void processs(){
    ll n;
    cin>>n;
    G g(n);
    mytl::readEdgeList(g, n-1);

    auto enyem_ = mytl::readValues<ll>(mytl::read<ll>());
    set<ll> enyem(enyem.begin(), enyem.end());
    auto ove_ = mytl::readValues<ll>(mytl::read<ll>());
    set<ll> ove(ove.begin(), ove.end());
    auto ask = [&](ll& ide, char tipus, ll ki) -> bool{
        cout<<tipus<<" "<<ki<<endl;
        ll got;
        cin>>got;
        if(tipus == 'A' && mytl::has_key(ove, got)){
            cout<<"C "<<ki<<endl;
            return true;
        }
        if(tipus == 'B' && mytl::has_key(enyem, got)){
            cout<<"C "<<got<<endl;
            return true;
        }
        ide = got;
        return false;

    };

    ll one_piece;
    if(ask(one_piece, 'B', *ove.begin())) return;

    auto tb = mytl::queue_graph_algorithm<G, mytl::AlgoComposer<mytl::FILO,mytl::SimpleLengthAndLastNode>::A >(g, vector<pair<pair<ll,ll>, ll> >{{{0,-1}, *enyem.begin()}});

    while(!mytl::has_key(enyem, one_piece)){
        one_piece = tb[one_piece].second;
    }

    ll dc;
    if(ask(dc, 'A', one_piece)) return;
    else{
        cout<<"C -1"<<endl;
    }

}

MAIN main(){
    ll T;
    cin>>T;
    mytl::repeat(T, [&](){
        processs();
    }) ;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fk1tread ios_bk1e::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

vector<int>g[1001];
vector<int> dist;

void bfs(int src, int k2){
	queue<int> q;
	q.push(src);
	dist[src] = 1;
	while(!q.empty()){
		int u = q.front();
		q.pop();
		for(int v:g[u]){
			if(dist[v] != -1) continue;
			dist[v] = dist[u] + 1;
			if(dist[v] < k2){
				q.push(v);
			}
		}
	}
}

void solve(){
	int n;
	cin>>n;
	dist= vector<int> (n+1,-1);
	for(int i=0;i<1001;i++){
		g[i].clear();
	}
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	int k1;
	cin>>k1; vector<int> s1(k1);
	for(int i=0;i<k1;i++){
		cin>>s1[i];
	}
	int k2;
	cin>>k2;
	vector<int> s2(k2);
	for(int i=0;i<k2;i++){
		cin>>s2[i];
	}

	cout<<"B "<<s2[0]<<endl;
	fflush(stdout);
	int src;
	cin>>src;

	for(int i=0;i<k1;i++){
		if(src == s1[i]){
			cout<<"C "<<src<<endl;
			fflush(stdout);
			return;
		}
	}

	bfs(src,k2);
	int ask;
	int resp;
	for(int i=0;i<k1;i++){
		if(dist[s1[i]] != -1){
			ask = s1[i];
			cout<<"A "<<s1[i]<<endl;
			fflush(stdout);
			cin>>resp;
			for(int i=0;i<k2;i++){
				if(resp == s2[i]){
					cout<<"C "<<ask<<endl;
					fflush(stdout);
					return;
				}
			}
		}
	}

	cout<<"C -1"<<endl;
	fflush(stdout);

}

int main(){
	int t;
	cin>>t;
	while(t--)
		solve();
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fk1tread ios_bk1e::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

vector<int>g[5001];
vector<int> dist;

void bfs(int src, int k2){
	queue<int> q;
	q.push(src);
	dist[src] = 1;
	while(!q.empty()){
		int u = q.front();
		q.pop();
		for(int v:g[u]){
			if(dist[v] != -1) continue;
			dist[v] = dist[u] + 1;
			if(dist[v] < k2){
				q.push(v);
			}
		}
	}
}

void solve(){
	int n;
	cin>>n;
	dist= vector<int> (n+1,-1);
	for(int i=0;i<5001;i++){
		g[i].clear();
	}
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	int k1;
	cin>>k1; vector<int> s1(k1);
	for(int i=0;i<k1;i++){
		cin>>s1[i];
	}
	int k2;
	cin>>k2;
	vector<int> s2(k2);
	for(int i=0;i<k2;i++){
		cin>>s2[i];
	}

	cout<<"B "<<s2[0]<<endl;
	fflush(stdout);
	int src;
	cin>>src;

	for(int i=0;i<k1;i++){
		if(src == s1[i]){
			cout<<"C "<<src<<endl;
			fflush(stdout);
			return;
		}
	}

	bfs(src,k2);
	int ask;
	int resp;
	for(int i=0;i<k1;i++){
		if(dist[s1[i]] != -1){
			ask = s1[i];
			cout<<"A "<<s1[i]<<endl;
			fflush(stdout);
			cin>>resp;
			for(int i=0;i<k2;i++){
				if(resp == s2[i]){
					cout<<"C "<<ask<<endl;
					fflush(stdout);
					return;
				}
			}
			break;
		}
	}

	cout<<"C -1"<<endl;
	fflush(stdout);

}

int main(){
	int t;
	cin>>t;
	while(t--)
		solve();
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fk1tread ios_bk1e::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

vector<int>g[5001];
vector<int> dist;

void bfs(int src, int k2){
	queue<int> q;
	q.push(src);
	dist[src] = 1;
	while(!q.empty()){
		int u = q.front();
		q.pop();
		for(int v:g[u]){
			if(dist[v] != -1) continue;
			dist[v] = dist[u] + 1;
			if(dist[v] < k2){
				q.push(v);
			}
		}
	}
}

void solve(){
	int n;
	cin>>n;
	dist= vector<int> (n+1,-1);
	for(int i=0;i<5001;i++){
		g[i].clear();
	}
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	int k1;
	cin>>k1; vector<int> s1(k1);
	for(int i=0;i<k1;i++){
		cin>>s1[i];
	}
	int k2;
	cin>>k2;
	vector<int> s2(k2);
	for(int i=0;i<k2;i++){
		cin>>s2[i];
	}

	cout<<"B "<<s2[0]<<endl;
	fflush(stdout);
	int src;
	cin>>src;

	for(int i=0;i<k1;i++){
		if(src == s1[i]){
			cout<<"C "<<src<<endl;
			fflush(stdout);
			return;
		}
	}

	bfs(src,k2);
	int ask=-1;
	int resp=-1;
	int dis = INT_MAX;
	for(int i=0;i<k1;i++){
		if(dist[s1[i]] != -1){
			if(dist[s1[i]]<dis){
				ask = s1[i];
				dis = dist[ask];
			}
		}
	}
	if(ask == -1){
		cout<<"C -1"<<endl;
	}

	cout<<"A "<<ask<<endl;
	fflush(stdout);
	cin>>resp;

	for(int i=0;i<k2;i++){
		if(resp == s2[i]){
			cout<<"C "<<ask<<endl;
			fflush(stdout);
			return;
		}
	}

	cout<<"C -1"<<endl;
	fflush(stdout);

}

int main(){
	int t;
	cin>>t;
	while(t--)
		solve();
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fk1tread ios_bk1e::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

vector<int>g[1001];
vector<int> dist;

void bfs(int src, int k2){
	queue<int> q;
	q.push(src);
	dist[src] = 0;
	while(!q.empty()){
		int u = q.front();
		q.pop();
		for(int v:g[u]){
			if(dist[v] != -1) continue;
			dist[v] = dist[u] + 1;
			if(dist[v] < k2){
				q.push(v);
			}
		}
	}
}

void solve(){
	int n;
	cin>>n;
	dist= vector<int> (n+1,-1);
	for(int i=0;i<1001;i++){
		g[i].clear();
	}
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	int k1;
	cin>>k1; vector<int> s1(k1);
	for(int i=0;i<k1;i++){
		cin>>s1[i];
	}
	int k2;
	cin>>k2;
	vector<int> s2(k2);
	for(int i=0;i<k2;i++){
		cin>>s2[i];
	}

	cout<<"B "<<s2[0]<<endl;
	fflush(stdout);
	int src;
	cin>>src;

	for(int i=0;i<k1;i++){
		if(src == s1[i]){
			cout<<"C "<<src<<endl;
			fflush(stdout);
			return;
		}
	}

	bfs(src,k2);
	int ask;
	int resp;
	for(int i=0;i<k1;i++){
		if(dist[s1[i]] != -1){
			ask = s1[i];
			cout<<"A "<<s1[i]<<endl;
			fflush(stdout);
			cin>>resp;
			break;
		}
	}

	for(int i=0;i<k2;i++){
		if(resp == s2[i]){
			cout<<"C "<<ask<<endl;
			fflush(stdout);
			return;
		}
	}

	cout<<"C -1"<<endl;
	fflush(stdout);

}

int main(){
	int t;
	cin>>t;
	while(t--)
		solve();
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fk1tread ios_bk1e::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

vector<int>g[1001];
vector<int> dist;

void bfs(int src, int k2){
	queue<int> q;
	q.push(src);
	dist[src] = 1;
	while(!q.empty()){
		int u = q.front();
		q.pop();
		for(int v:g[u]){
			if(dist[v] != -1) continue;
			dist[v] = dist[u] + 1;
			if(dist[v] < k2){
				q.push(v);
			}
		}
	}
}

void solve(){
	int n;
	cin>>n;
	dist= vector<int> (n+1,-1);
	for(int i=0;i<1001;i++){
		g[i].clear();
	}
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	int k1;
	cin>>k1; vector<int> s1(k1);
	for(int i=0;i<k1;i++){
		cin>>s1[i];
	}
	int k2;
	cin>>k2;
	vector<int> s2(k2);
	for(int i=0;i<k2;i++){
		cin>>s2[i];
	}

	cout<<"B "<<s2[0]<<endl;
	fflush(stdout);
	int src;
	cin>>src;

	for(int i=0;i<k1;i++){
		if(src == s1[i]){
			cout<<"C "<<src<<endl;
			fflush(stdout);
			return;
		}
	}

	bfs(src,k2);
	int ask;
	int resp;
	for(int i=0;i<k1;i++){
		if(dist[s1[i]] != -1){
			ask = s1[i];
			cout<<"A "<<s1[i]<<endl;
			fflush(stdout);
			cin>>resp;
			break;
		}
	}

	for(int i=0;i<k2;i++){
		if(resp == s2[i]){
			cout<<"C "<<ask<<endl;
			fflush(stdout);
			return;
		}
	}

	cout<<"C -1"<<endl;
	fflush(stdout);

}

int main(){
	int t;
	cin>>t;
	while(t--)
		solve();
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fk1tread ios_bk1e::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

vector<int>g[5001];
vector<int> dist;

void bfs(int src, int k2){
	queue<int> q;
	q.push(src);
	dist[src] = 1;
	while(!q.empty()){
		int u = q.front();
		q.pop();
		for(int v:g[u]){
			if(dist[v] != -1) continue;
			dist[v] = dist[u] + 1;
			if(dist[v] < k2){
				q.push(v);
			}
		}
	}
}

void solve(){
	int n;
	cin>>n;
	dist= vector<int> (n+1,-1);
	for(int i=0;i<5001;i++){
		g[i].clear();
	}
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	int k1;
	cin>>k1; vector<int> s1(k1);
	for(int i=0;i<k1;i++){
		cin>>s1[i];
	}
	int k2;
	cin>>k2;
	vector<int> s2(k2);
	for(int i=0;i<k2;i++){
		cin>>s2[i];
	}

	cout<<"B "<<s2[0]<<endl;
	fflush(stdout);
	int src;
	cin>>src;

	for(int i=0;i<k1;i++){
		if(src == s1[i]){
			cout<<"C "<<src<<endl;
			fflush(stdout);
			return;
		}
	}

	bfs(src,k2);
	int ask=-1;
	int resp=-1;
	int dis = INT_MAX;
	for(int i=0;i<k1;i++){
		if(dist[s1[i]] != -1){
			if(dist[s1[i]]<dis){
				ask = s1[i];
				dis = dist[ask];
			}
		}
	}
	if(ask == -1){
		cout<<"C -1"<<endl;
	}

	cout<<"A "<<s1[i]<<endl;
	fflush(stdout);
	cin>>resp;

	for(int i=0;i<k2;i++){
		if(resp == s2[i]){
			cout<<"C "<<ask<<endl;
			fflush(stdout);
			return;
		}
	}

	cout<<"C -1"<<endl;
	fflush(stdout);

}

int main(){
	int t;
	cin>>t;
	while(t--)
		solve();
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fk1tread ios_bk1e::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

vector<int>g[5001];
vector<int> dist;

void bfs(int src, int k2){
	queue<int> q;
	q.push(src);
	dist[src] = 1;
	while(!q.empty()){
		int u = q.front();
		q.pop();
		for(int v:g[u]){
			if(dist[v] != -1) continue;
			dist[v] = dist[u] + 1;
			if(dist[v] < k2){
				q.push(v);
			}
		}
	}
}

void solve(){
	int n;
	cin>>n;
	dist= vector<int> (n+1,-1);
	for(int i=0;i<5001;i++){
		g[i].clear();
	}
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	int k1;
	cin>>k1; vector<int> s1(k1);
	for(int i=0;i<k1;i++){
		cin>>s1[i];
	}
	int k2;
	cin>>k2;
	vector<int> s2(k2);
	for(int i=0;i<k2;i++){
		cin>>s2[i];
	}

	cout<<"B "<<s2[0]<<endl;
	fflush(stdout);
	int src;
	cin>>src;

	for(int i=0;i<k1;i++){
		if(src == s1[i]){
			cout<<"C "<<src<<endl;
			fflush(stdout);
			return;
		}
	}

	bfs(src,k2);
	int ask=-1;
	int resp=-1;
	int dis = INT_MAX;
	for(int i=0;i<k1;i++){
		if(dist[s1[i]] != -1){
			if(dist[s1[i]]<dis){
				ask = s1[i];
				dis = dist[ask];
			}
		}
	}
	if(ask == -1){
		cout<<"C -1"<<endl;
		return;
	}

	cout<<"A "<<ask<<endl;
	fflush(stdout);
	cin>>resp;

	for(int i=0;i<k2;i++){
		if(resp == s2[i]){
			cout<<"C "<<ask<<endl;
			fflush(stdout);
			return;
		}
	}

	cout<<"C -1"<<endl;
	fflush(stdout);

}

int main(){
	int t;
	cin>>t;
	while(t--)
		solve();
}


#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod 1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double
#define N 1025

vii g(N);
int par[N],subs[N],level[N];
vii dp(N,vector<int>(11));
void createlca(int n)
{
    for(int i=1;i<=n;i++)
        dp[i][0]=par[i];
    for(int j=1;j<10;j++)
    {
        for(int i=1;i<=n;i++)
        {
            dp[i][j]=dp[dp[i][j-1]][j-1];
        }
    }
}
int LCA(int u,int v)
{

    if(level[u]<level[v])
        swap(u,v);
    if(level[u]!=level[v])
    {
        for(int j=10;j>=0;j--)
        {

            if(level[dp[u][j]]>=level[v])
                u=dp[u][j];

        }
    }

    if(u==v)
        return u;
    for(int j=10;j>=0;j--)
    {
        if(dp[u][j]!=dp[v][j])
        {
            u=dp[u][j];
            v=dp[v][j];
        }
    }
    return par[u];
}
void dfs(int s,int p)
{
    par[s]=p;
    level[s]=level[p]+1;

    for(int i=0;i<g[s].size();i++)
    {
        if(g[s][i]!=p)
        {

            dfs(g[s][i],s);
        }
    }
}
int32_t main()
{
	IOS;
	/*#ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif*/
    int t;
    cin>>t;
    while(t--)
    {
    	int n;
    	cin>>n;
    	g.clear();
    	g.resize(n+1);
    	for(int i=1;i<=n-1;i++)
    	{
    		int a,b;
    		cin>>a>>b;
    		g[a].pb(b);
    		g[b].pb(a);
    	};

    	int k1;
    	cin>>k1;
    	int flca;
    	vi v1(k1);

    	for(int i=0;i<k1;i++)
    	{
    		cin>>v1[i];
    		flca=v1[i];
    	}
    	level[flca]=0;
    	dfs(flca,flca);
    	createlca(n);

    	int k2;
    	cin>>k2;
    	vi v2(k2);
    	int nlca;
    	for(int i = 0 ;i<k2;i++ )
    	{
    		cin>>v2[i];

    	}
    	cout<<"A "<<flca<<endl;
    	int resp;
    	cin>>resp;
    	bool ch=0;
    	for(int i=0;i<k2;i++)
    	{
    		if(resp==v2[i])
    		{
    			cout<<"C "<<flca<<endl;
    			ch=1;
    		}
    	}
    	if(ch==0)
    	{
    		cout<<"B "<<v2[0]<<endl;
    		cin>>resp;
    		if(k2==1)
    		{
    			for(int i=0;i<k1;i++)
    			{
    				if(resp==v1[i])
    					{cout<<"C "<<resp<<endl;ch=1;}
    			}
    		}
    		else
    		{
    			cout<<"B "<<v2[1]<<endl;
    			int node1=resp;
    			int node2;
    			cin>>node2;
    			if(level[node2]<level[node1])
    				swap(node2,node1);
    			while(level[node2]>level[node1])
    			{
    				node2=par[node2];
    			}
    			while(node2!=node1)
    			{
    				node1=par[node1];
    				node2=par[node2];
    			}
    			for(int i=0;i<k1;i++)
    			{
    				if(v1[i]==node2)
    				{
    					cout<<"A "<<node2<<endl;
    					ch=1;
    				}
    			}
    		}

    	}
    	if(ch==0)
    		cout<<"C -1"<<endl;
    }

	return 0;
}


#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod 1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double
#define N 1025

vii g(N);
int par[N],subs[N],level[N];
vii dp(N,vector<int>(11));
void createlca(int n)
{
    for(int i=1;i<=n;i++)
        dp[i][0]=par[i];
    for(int j=1;j<10;j++)
    {
        for(int i=1;i<=n;i++)
        {
            dp[i][j]=dp[dp[i][j-1]][j-1];
        }
    }
}
int LCA(int u,int v)
{

    if(level[u]<level[v])
        swap(u,v);
    if(level[u]!=level[v])
    {
        for(int j=10;j>=0;j--)
        {

            if(level[dp[u][j]]>=level[v])
                u=dp[u][j];

        }
    }

    if(u==v)
        return u;
    for(int j=10;j>=0;j--)
    {
        if(dp[u][j]!=dp[v][j])
        {
            u=dp[u][j];
            v=dp[v][j];
        }
    }
    return par[u];
}
void dfs(int s,int p)
{
    par[s]=p;
    level[s]=level[p]+1;

    for(int i=0;i<g[s].size();i++)
    {
        if(g[s][i]!=p)
        {

            dfs(g[s][i],s);
        }
    }
}
int32_t main()
{
	IOS;
	/*#ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif*/
    int t;
    cin>>t;
    while(t--)
    {
    	int n;
    	cin>>n;
    	g.clear();
    	g.resize(n+1);
    	for(int i=1;i<=n-1;i++)
    	{
    		int a,b;
    		cin>>a>>b;
    		g[a].pb(b);
    		g[b].pb(a);
    	};

    	int k1;
    	cin>>k1;
    	int flca;
    	vi v1(k1);

    	for(int i=0;i<k1;i++)
    	{
    		cin>>v1[i];
    		flca=v1[i];

    	}

    	int k2;
    	cin>>k2;
    	vi v2(k2);
    	int nlca;

    	for(int i = 0 ;i<k2;i++ )
    	{
    		cin>>v2[i];

    	}
    	cout<<"B "<<v2[0]<<endl;
    	cout.flush();
    	int resp;
    	cin>>resp;
    	level[resp]=0;
    	dfs(resp,resp);
    	createlca(n);
    	int query=v1[0];
    	int lev=10000;
    	for(int i=0;i<k1;i++)
    	{
    		if(level[query]>level[v1[i]])
    			query=v1[i];
    	}

    	cout<<"A "<<query<<endl;
    	cin>>resp;
    	bool ch=0;
    	for(int i=0;i<k2;i++)
    	{
    		if(resp==v2[i])
    		{
    			ch=1;
    			cout<<"C "<<query<<endl;
    			break;
    		}
    	}
    	if(ch==0)
    		{cout<<"C -1"<<endl;cout.flush();}
    }

	return 0;
}


#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod 1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double
#define N 1025

vii g(N);
int par[N],subs[N],level[N];
vii dp(N,vector<int>(11));
void createlca(int n)
{
    for(int i=1;i<=n;i++)
        dp[i][0]=par[i];
    for(int j=1;j<10;j++)
    {
        for(int i=1;i<=n;i++)
        {
            dp[i][j]=dp[dp[i][j-1]][j-1];
        }
    }
}
int LCA(int u,int v)
{

    if(level[u]<level[v])
        swap(u,v);
    if(level[u]!=level[v])
    {
        for(int j=10;j>=0;j--)
        {

            if(level[dp[u][j]]>=level[v])
                u=dp[u][j];

        }
    }

    if(u==v)
        return u;
    for(int j=10;j>=0;j--)
    {
        if(dp[u][j]!=dp[v][j])
        {
            u=dp[u][j];
            v=dp[v][j];
        }
    }
    return par[u];
}
void dfs(int s,int p)
{
    par[s]=p;
    level[s]=level[p]+1;

    for(int i=0;i<g[s].size();i++)
    {
        if(g[s][i]!=p)
        {

            dfs(g[s][i],s);
        }
    }
}
int32_t main()
{
	IOS;
	/*#ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif*/
    int t;
    cin>>t;
    while(t--)
    {
    	int n;
    	cin>>n;
    	g.clear();
    	g.resize(n+1);
    	for(int i=1;i<=n-1;i++)
    	{
    		int a,b;
    		cin>>a>>b;
    		g[a].pb(b);
    		g[b].pb(a);
    	};

    	int k1;
    	cin>>k1;
    	int flca;
    	vi v1(k1);
    	set<int> s1;
    	for(int i=0;i<k1;i++)
    	{
    		cin>>v1[i];
    		flca=v1[i];
    		s1.insert(v1[i]);
    	}
    	level[flca]=0;
    	dfs(flca,flca);
    	createlca(n);

    	int k2;
    	cin>>k2;
    	vi v2(k2);
    	int nlca;
    	set<int> s2;
    	for(int i = 0 ;i<k2;i++ )
    	{
    		cin>>v2[i];
    		s2.insert(v2[i]);

    	}
    	cout<<"A "<<flca<<endl;
    	cout.flush();
    	int resp;
    	cin>>resp;
    	bool ch=0;
    	for(int i=0;i<k2;i++)
    	{
    		if(resp==v2[i])
    		{
    			cout<<"C "<<flca<<endl;
    			cout.flush();

    			ch=1;
    			break;
    		}
    	}
    	if(ch==0)
    	{
    		cout<<"B "<<v2[0]<<endl;
    		cout.flush();
    		cin>>resp;
    		if(k2==1)
    		{
    			for(int i=0;i<k1;i++)
    			{
    				if(resp==v1[i])
    					{cout<<"C "<<resp<<endl;cout.flush();ch=1;break;}
    			}
    		}
    		else
    		{
    			cout<<"B "<<v2[1]<<endl;
    			cout.flush();
    			int node1=resp;
    			int node2;
    			cin>>node2;
    			if(level[node2]<level[node1])
    				swap(node2,node1);
    			while(level[node2]>level[node1])
    			{
    				node2=par[node2];
    			}
    			while(node2!=node1)
    			{
    				node1=par[node1];
    				node2=par[node2];
    			}

    			for(int i=0;i<k1;i++)
    			{

    				int lc=LCA(node2,v1[i]);
    				if(s1.find(lc)!=s1.end())
    				{
    					cout<<"A "<<lc<<endl;
    					cout.flush();
    					cin>>resp;
    					if(s2.find(resp)!=s2.end())
    					{
    						cout<<"C "<<lc<<endl;
    						ch=1;
    						break;
    					}
    					else
    						break;
    				}
    			}
    		}

    	}
    	if(ch==0)
    		{cout<<"C -1"<<endl;cout.flush();}
    }

	return 0;
}


#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod 1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double
#define N 1025

vii g(N);
int par[N],subs[N],level[N];
vii dp(N,vector<int>(11));
void createlca(int n)
{
    for(int i=1;i<=n;i++)
        dp[i][0]=par[i];
    for(int j=1;j<10;j++)
    {
        for(int i=1;i<=n;i++)
        {
            dp[i][j]=dp[dp[i][j-1]][j-1];
        }
    }
}
int LCA(int u,int v)
{

    if(level[u]<level[v])
        swap(u,v);
    if(level[u]!=level[v])
    {
        for(int j=10;j>=0;j--)
        {

            if(level[dp[u][j]]>=level[v])
                u=dp[u][j];

        }
    }

    if(u==v)
        return u;
    for(int j=10;j>=0;j--)
    {
        if(dp[u][j]!=dp[v][j])
        {
            u=dp[u][j];
            v=dp[v][j];
        }
    }
    return par[u];
}
void dfs(int s,int p)
{
    par[s]=p;
    level[s]=level[p]+1;

    for(int i=0;i<g[s].size();i++)
    {
        if(g[s][i]!=p)
        {

            dfs(g[s][i],s);
        }
    }
}
int32_t main()
{
	IOS;
	/*#ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif*/
    int t;
    cin>>t;
    while(t--)
    {
    	int n;
    	cin>>n;
    	g.clear();
    	g.resize(n+1);
    	for(int i=1;i<=n-1;i++)
    	{
    		int a,b;
    		cin>>a>>b;
    		g[a].pb(b);
    		g[b].pb(a);
    	};

    	int k1;
    	cin>>k1;
    	int flca;
    	vi v1(k1);

    	for(int i=0;i<k1;i++)
    	{
    		cin>>v1[i];
    		flca=v1[i];
    	}
    	level[flca]=0;
    	dfs(flca,flca);
    	createlca(n);

    	int k2;
    	cin>>k2;
    	vi v2(k2);
    	int nlca;
    	for(int i = 0 ;i<k2;i++ )
    	{
    		cin>>v2[i];

    	}
    	cout<<"A "<<flca<<endl;
    	cout.flush();
    	int resp;
    	cin>>resp;
    	bool ch=0;
    	for(int i=0;i<k2;i++)
    	{
    		if(resp==v2[i])
    		{
    			cout<<"C "<<flca<<endl;
    			cout.flush();

    			ch=1;
    		}
    	}
    	if(ch==0)
    	{
    		cout<<"B "<<v2[0]<<endl;
    		cout.flush();
    		cin>>resp;
    		if(k2==1)
    		{
    			for(int i=0;i<k1;i++)
    			{
    				if(resp==v1[i])
    					{cout<<"C "<<resp<<endl;cout.flush();ch=1;}
    			}
    		}
    		else
    		{
    			cout<<"B "<<v2[1]<<endl;
    			cout.flush();
    			int node1=resp;
    			int node2;
    			cin>>node2;
    			if(level[node2]<level[node1])
    				swap(node2,node1);
    			while(level[node2]>level[node1])
    			{
    				node2=par[node2];
    			}
    			while(node2!=node1)
    			{
    				node1=par[node1];
    				node2=par[node2];
    			}
    			for(int i=0;i<k1;i++)
    			{
    				if(v1[i]==node2)
    				{
    					cout<<"A "<<node2<<endl;
    					cout.flush();
    					ch=1;
    				}
    			}
    		}

    	}
    	if(ch==0)
    		{cout<<"C -1"<<endl;cout.flush();}
    }

	return 0;
}


#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod 1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double
#define N 1025

vii g(N);
int par[N],subs[N],level[N];
vii dp(N,vector<int>(11));
void createlca(int n)
{
    for(int i=1;i<=n;i++)
        dp[i][0]=par[i];
    for(int j=1;j<10;j++)
    {
        for(int i=1;i<=n;i++)
        {
            dp[i][j]=dp[dp[i][j-1]][j-1];
        }
    }
}
int LCA(int u,int v)
{

    if(level[u]<level[v])
        swap(u,v);
    if(level[u]!=level[v])
    {
        for(int j=10;j>=0;j--)
        {

            if(level[dp[u][j]]>=level[v])
                u=dp[u][j];

        }
    }

    if(u==v)
        return u;
    for(int j=10;j>=0;j--)
    {
        if(dp[u][j]!=dp[v][j])
        {
            u=dp[u][j];
            v=dp[v][j];
        }
    }
    return par[u];
}
void dfs(int s,int p)
{
    par[s]=p;
    level[s]=level[p]+1;

    for(int i=0;i<g[s].size();i++)
    {
        if(g[s][i]!=p)
        {

            dfs(g[s][i],s);
        }
    }
}
int32_t main()
{
	IOS;
	/*#ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif*/
    int t;
    cin>>t;
    while(t--)
    {
    	int n;
    	cin>>n;
    	g.clear();
    	g.resize(n+1);
    	for(int i=1;i<=n-1;i++)
    	{
    		int a,b;
    		cin>>a>>b;
    		g[a].pb(b);
    		g[b].pb(a);
    	};

    	int k1;
    	cin>>k1;
    	int flca;
    	vi v1(k1);

    	for(int i=0;i<k1;i++)
    	{
    		cin>>v1[i];
    		flca=v1[i];

    	}

    	int k2;
    	cin>>k2;
    	vi v2(k2);
    	int nlca;

    	for(int i = 0 ;i<k2;i++ )
    	{
    		cin>>v2[i];

    	}
    	cout<<"B "<<v2[0]<<endl;
    	cout.flush();
    	int resp;
    	cin>>resp;
    	level[resp]=0;
    	dfs(resp,resp);
    	createlca(n);
    	int query=v1[0];
    	int lev=10000;
    	for(int i=0;i<k1;i++)
    	{
    		if(level[query]>level[v1[i]])
    			query=v1[i];
    	}

    	cout<<"A "<<query<<endl;
    	cin>>resp;
    	bool ch=1;
    	for(int i=0;i<k2;i++)
    	{
    		if(resp==v2[i])
    		{
    			ch=1;
    			cout<<"C "<<query<<endl;
    			break;
    		}
    	}
    	if(ch==0)
    		{cout<<"C -1"<<endl;cout.flush();}
    }

	return 0;
}


#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod 1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double
#define N 1025

vii g(N);
int par[N],subs[N],level[N];
vii dp(N,vector<int>(11));
void createlca(int n)
{
    for(int i=1;i<=n;i++)
        dp[i][0]=par[i];
    for(int j=1;j<10;j++)
    {
        for(int i=1;i<=n;i++)
        {
            dp[i][j]=dp[dp[i][j-1]][j-1];
        }
    }
}
int LCA(int u,int v)
{

    if(level[u]<level[v])
        swap(u,v);
    if(level[u]!=level[v])
    {
        for(int j=10;j>=0;j--)
        {

            if(level[dp[u][j]]>=level[v])
                u=dp[u][j];

        }
    }

    if(u==v)
        return u;
    for(int j=10;j>=0;j--)
    {
        if(dp[u][j]!=dp[v][j])
        {
            u=dp[u][j];
            v=dp[v][j];
        }
    }
    return par[u];
}
void dfs(int s,int p)
{
    par[s]=p;
    level[s]=level[p]+1;

    for(int i=0;i<g[s].size();i++)
    {
        if(g[s][i]!=p)
        {

            dfs(g[s][i],s);
        }
    }
}
int32_t main()
{
	IOS;
	/*#ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif*/
    int t;
    cin>>t;
    while(t--)
    {
    	int n;
    	cin>>n;
    	g.clear();
    	g.resize(n+1);
    	for(int i=1;i<=n-1;i++)
    	{
    		int a,b;
    		cin>>a>>b;
    		g[a].pb(b);
    		g[b].pb(a);
    	};

    	int k1;
    	cin>>k1;
    	int flca;
    	vi v1(k1);

    	for(int i=0;i<k1;i++)
    	{
    		cin>>v1[i];
    		flca=v1[i];
    	}
    	level[flca]=0;
    	dfs(flca,flca);
    	createlca(n);

    	int k2;
    	cin>>k2;
    	vi v2(k2);
    	int nlca;
    	for(int i = 0 ;i<k2;i++ )
    	{
    		cin>>v2[i];
    	}
    	cout<<"A "<<flca<<endl;
    	cout.flush();
    	int resp;
    	cin>>resp;
    	bool ch=0;
    	for(int i=0;i<k2;i++)
    	{
    		if(resp==v2[i])
    		{
    			cout<<"C "<<flca<<endl;
    			cout.flush();

    			ch=1;
    			break;
    		}
    	}
    	if(ch==0)
    	{
    		cout<<"B "<<v2[0]<<endl;
    		cout.flush();
    		cin>>resp;
    		if(k2==1)
    		{
    			for(int i=0;i<k1;i++)
    			{
    				if(resp==v1[i])
    					{cout<<"C "<<resp<<endl;cout.flush();ch=1;break;}
    			}
    		}
    		else
    		{
    			cout<<"B "<<v2[1]<<endl;
    			cout.flush();
    			int node1=resp;
    			int node2;
    			cin>>node2;
    			if(level[node2]<level[node1])
    				swap(node2,node1);
    			while(level[node2]>level[node1])
    			{
    				node2=par[node2];
    			}
    			while(node2!=node1)
    			{
    				node1=par[node1];
    				node2=par[node2];
    			}
    			for(int i=0;i<k1;i++)
    			{
    				if(v1[i]==node2)
    				{
    					cout<<"C "<<node2<<endl;
    					cout.flush();
    					ch=1;
    					break;
    				}
    			}
    		}

    	}
    	if(ch==0)
    		{cout<<"C -1"<<endl;cout.flush();}
    }

	return 0;
}


#include <algorithm>
#include  <iostream>
#include   <cstring>
#include    <string>
#include    <cstdio>
#include    <vector>
#include    <bitset>
#include     <stack>
#include     <queue>
#include     <cmath>
#include       <set>
#include       <map>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define clr(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define SZ(x) ((int)(x).size())
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
/*************head******************/
const int MAXN=1000+10;
vi G[MAXN];
int a[MAXN],b[MAXN];
bool vis[MAXN];
int bfs(int x){
    queue<int> que;
    que.push(x);
    clr(vis,0);
    vis[x]=true;
    while(!que.empty()){
        int now=que.front();
        que.pop();
        if(a[now]==1)return now;
        for(int i=0;i<G[now].size();i++){
            int v=G[now][i];
            if(vis[v])continue;
            que.push(v);
            vis[v]=true;
        }
    }
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int n;
        scanf("%d",&n);
        rep(i,1,n)G[i].clear();
        rep(i,1,n-1){
            int x,y;
            scanf("%d%d",&x,&y);
            G[x].pb(y);
            G[y].pb(x);
        }
        clr(a,0);
        clr(b,0);
        int w1;
        scanf("%d",&w1);
        rep(i,1,w1){
            int x;
            scanf("%d",&x);
            a[x]=1;
        }
        int w2;
        scanf("%d",&w2);
        int now;
        rep(i,1,w2){
            int x;
            scanf("%d",&x);
            b[x]=1;
            now=x;
        }
        printf("B %d\n",now);
        fflush(stdin);
        int id;
        scanf("%d",&id);
        id=bfs(id);
        printf("A %d\n",id);
        fflush(stdin);
        scanf("%d",&id);
        if(b[id]==1)puts("C 1");
        else puts("C -1");
        fflush(stdin);
    }
    return 0;
}


#include <algorithm>
#include  <iostream>
#include   <cstring>
#include    <string>
#include    <cstdio>
#include    <vector>
#include    <bitset>
#include     <stack>
#include     <queue>
#include     <cmath>
#include       <set>
#include       <map>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define clr(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define SZ(x) ((int)(x).size())
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
/*************head******************/
const int MAXN=1000+10;
vi G[MAXN];
int a[MAXN],b[MAXN];
bool vis[MAXN];
int bfs(int x){
    queue<int> que;
    que.push(x);
    clr(vis,0);
    vis[x]=true;
    while(!que.empty()){
        int now=que.front();
        que.pop();
        if(a[now]==1)return now;
        for(int i=0;i<G[now].size();i++){
            int v=G[now][i];
            if(vis[v])continue;
            que.push(v);
            vis[v]=true;
        }
    }
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int n;
        scanf("%d",&n);
        rep(i,1,n)G[i].clear();
        rep(i,1,n-1){
            int x,y;
            scanf("%d%d",&x,&y);
            G[x].pb(y);
            G[y].pb(x);
        }
        clr(a,0);
        clr(b,0);
        int w1;
        scanf("%d",&w1);
        rep(i,1,w1){
            int x;
            scanf("%d",&x);
            a[x]=1;
        }
        int w2;
        scanf("%d",&w2);
        int now;
        rep(i,1,w2){
            int x;
            scanf("%d",&x);
            b[x]=1;
            now=x;
        }
        printf("B %d\n",now);
        fflush(stdout);
        int id;
        scanf("%d",&id);
        id=bfs(id);
        printf("A %d\n",id);
        int ans=id;
        fflush(stdout);
        scanf("%d",&id);
        if(b[id]==1)printf("C %d\n",ans);
        else puts("C -1");
        fflush(stdout);
    }
    return 0;
}


#include <algorithm>
#include  <iostream>
#include   <cstring>
#include    <string>
#include    <cstdio>
#include    <vector>
#include    <bitset>
#include     <stack>
#include     <queue>
#include     <cmath>
#include       <set>
#include       <map>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define clr(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define SZ(x) ((int)(x).size())
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
/*************head******************/
const int MAXN=1000+10;
vi G[MAXN];
int a[MAXN],b[MAXN];
bool vis[MAXN];
int bfs(int x){
    queue<int> que;
    que.push(x);
    clr(vis,0);
    vis[x]=true;
    while(!que.empty()){
        int now=que.front();
        que.pop();
        if(a[now]==1)return now;
        for(int i=0;i<G[now].size();i++){
            int v=G[now][i];
            if(vis[v])continue;
            que.push(v);
            vis[v]=true;
        }
    }
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int n;
        scanf("%d",&n);
        rep(i,1,n)G[i].clear();
        rep(i,1,n-1){
            int x,y;
            scanf("%d%d",&x,&y);
            G[x].pb(y);
            G[y].pb(x);
        }
        clr(a,0);
        clr(b,0);
        int w1;
        scanf("%d",&w1);
        rep(i,1,w1){
            int x;
            scanf("%d",&x);
            a[x]=1;
        }
        int w2;
        scanf("%d",&w2);
        int now;
        rep(i,1,w2){
            int x;
            scanf("%d",&x);
            b[x]=1;
            now=x;
        }
        printf("B %d\n",now);
        fflush(stdout);
        int id;
        scanf("%d",&id);
        id=bfs(id);
        printf("A %d\n",id);
        int ans=id;
        fflush(stdout);
        scanf("%d",&id);
        if(b[id]==1)printf("C %d\n",,ans);
        else puts("C -1");
        fflush(stdout);
    }
    return 0;
}


#include <algorithm>
#include  <iostream>
#include   <cstring>
#include    <string>
#include    <cstdio>
#include    <vector>
#include    <bitset>
#include     <stack>
#include     <queue>
#include     <cmath>
#include       <set>
#include       <map>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define clr(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define SZ(x) ((int)(x).size())
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
/*************head******************/
const int MAXN=1000+10;
vi G[MAXN];
int a[MAXN],b[MAXN];
bool vis[MAXN];
int bfs(int x){
    queue<int> que;
    que.push(x);
    clr(vis,0);
    vis[x]=true;
    while(!que.empty()){
        int now=que.front();
        que.pop();
        if(a[now]==1)return now;
        for(int i=0;i<G[now].size();i++){
            int v=G[now][i];
            if(vis[v])continue;
            que.push(v);
            vis[v]=true;
        }
    }
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int n;
        scanf("%d",&n);
        rep(i,1,n)G[i].clear();
        rep(i,1,n-1){
            int x,y;
            scanf("%d%d",&x,&y);
            G[x].pb(y);
            G[y].pb(x);
        }
        clr(a,0);
        clr(b,0);
        int w1;
        scanf("%d",&w1);
        rep(i,1,w1){
            int x;
            scanf("%d",&x);
            a[x]=1;
        }
        int w2;
        scanf("%d",&w2);
        int now;
        rep(i,1,w2){
            int x;
            scanf("%d",&x);
            b[x]=1;
            now=x;
        }
        printf("B %d\n",now);
        fflush(stdout);
        int id;
        scanf("%d",&id);
        id=bfs(id);
        printf("A %d\n",id);
        fflush(stdout);
        scanf("%d",&id);
        if(b[id]==1)puts("C 1");
        else puts("C -1");
        fflush(stdout);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long t,n,k,minn=INT_MAX,maxx=-1,sum=0,k1,k2,a[200005],b[200005],h[2000005],c[200005],cnt[1005],pos,dp[1005],pos2,vis[1005],d,dd;
vector<int> v[1005];
map<pair<int,int>,int> m;
pair<int,int> p;
string s;
void dfs(int x)
{
    vis[x]=1;
    for(int ii=0;ii<cnt[x];ii++)
    {
        if(vis[v[x][ii]]==0)
        {
            dp[v[x][ii]]=dp[x]+1;
            dfs(v[x][ii]);
        }
    }
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    for(int i=0;i<1002;i++)
    {
        cnt[i]=0;
        vis[i]=0;
    }
    cin>>t;
    while(t--)
    {
        d=1;
        dd=1;
        minn=INT_MAX;
        cin>>n;
        for(int i=0;i<n-1;i++)
        {
            cin>>a[i]>>b[i];
            cnt[a[i]]++;
            cnt[b[i]]++;
            v[a[i]].push_back(b[i]);
            v[b[i]].push_back(a[i]);
        }
        cin>>k1;
        for(int i=0;i<k1;i++)
        {
            cin>>a[i];
        }
        cin>>k2;
        for(int i=0;i<k2;i++)
        {
            cin>>b[i];
        }
        cout<<"B "<<b[0]<<endl;
        cin>>pos;
        for(int i=0;i<k1;i++)
        {
            if(a[i]==pos)
            {
                cout<<"C "<<pos<<endl;
                d=0;
            }
        }
        if(d)
        {
            dp[pos]=0;
        dfs(pos);
        pos2=0;
        for(int i=0;i<k1;i++)
        {
            if(dp[a[i]]<minn)
            {
                pos2=a[i];
                minn=dp[a[i]];
            }
        }
        cout<<"A "<<pos2<<endl;
        cin>>pos;
        for(int i=0;i<k2;i++)
        {
            if(b[i]==pos)
            {
                cout<<"C "<<pos2<<endl;
                dd=0;
            }
        }
        if(dd)
        {
            cout<<"C "<<-1<<endl;
        }

        }
        for(int i=0;i<=n;i++)
        {
            vis[i]=0;
            dp[i]=0;
            cnt[i]=0;
        }

    }
}


#include<bits/stdc++.h>
using namespace std;
long long t,n,k,minn=INT_MAX,maxx=-1,sum=0,k1,k2,a[200005],b[200005],h[2000005],c[200005],cnt[1005],pos,dp[1005],pos2,vis[1005],d,dd,ha;
vector<int> v[1005];
map<pair<int,int>,int> m;
pair<int,int> p;
string s;
void dfs(int x)
{
    vis[x]=1;
    for(int ii=0;ii<cnt[x];ii++)
    {
        if(vis[v[x][ii]]==0)
        {
            dp[v[x][ii]]=dp[x]+1;
            dfs(v[x][ii]);
        }
    }
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    for(int i=0;i<1002;i++)
    {
        cnt[i]=0;
        vis[i]=0;
    }
    cin>>t;
    ha=t;
    while(t--)
    {
        d=1;
        dd=1;
        minn=INT_MAX;
        cin>>n;
        for(int i=0;i<n-1;i++)
        {
            cin>>c[i]>>h[i];
            cnt[c[i]]++;
            cnt[h[i]]++;
            v[c[i]].push_back(h[i]);
            v[h[i]].push_back(c[i]);
        }
        cin>>k1;
        for(int i=0;i<k1;i++)
        {
            cin>>a[i];
        }
        cin>>k2;
        for(int i=0;i<k2;i++)
        {
            cin>>b[i];
        }
        cout<<"B "<<b[0]<<endl;
        cin>>pos;
        for(int i=0;i<k1;i++)
        {
            if(a[i]==pos)
            {
                cout<<"C "<<pos<<endl;
                d=0;
            }
        }
        if(d)
        {
            dp[pos]=0;
        dfs(pos);
        pos2=0;
        for(int i=0;i<k1;i++)
        {
            if(dp[a[i]]<minn)
            {
                pos2=a[i];
                minn=dp[a[i]];
            }
        }
        cout<<"A "<<pos2<<endl;
        cin>>pos;
        for(int i=0;i<k2;i++)
        {
            if(b[i]==pos)
            {
                cout<<"C "<<pos2<<endl;
                dd=0;
            }
        }
        if(dd)
        {
            cout<<"C "<<-1<<endl;
        }

        }
        for(int i=0;i<=n;i++)
        {
            vis[i]=0;
            dp[i]=0;
            cnt[i]=0;
        }
        if(ha-t==8)
        {
            cout<<n<<endl;
            for(int i=0;i<n-1;i++)
            {
                cout<<c[i]<<" "<<h[i]<<endl;
            }
            cout<<k1;
            for(int i=0;i<k1;i++)
            {
                cout<<a[i]<<" ";
            }
            cout<<endl;
            cout<<k2;
            for(int i=0;i<k2;i++)
            {
                cout<<b[i];
            }
            cout<<endl;
        }

    }
}


#include<bits/stdc++.h>
using namespace std;
long long t,n,k,minn=INT_MAX,maxx=-1,sum=0,k1,k2,a[200005],b[200005],h[2000005],c[200005],cnt[1005],pos,dp[1005],pos2,vis[1005],d,dd,ha,v[1005][1005];
map<pair<int,int>,int> m;
pair<int,int> p;
string s;
void dfs(int x)
{
    vis[x]=1;
    for(int ii=0;ii<cnt[x];ii++)
    {
        if(vis[v[x][ii]]==0)
        {
            dp[v[x][ii]]=dp[x]+1;
            dfs(v[x][ii]);
        }
    }
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    for(int i=0;i<1002;i++)
    {
        cnt[i]=0;
        vis[i]=0;
    }
    cin>>t;
    ha=t;
    while(t--)
    {
        d=1;
        dd=1;
        pos=0;
        pos2=0;
        minn=INT_MAX;
        cin>>n;
        for(int i=0;i<n-1;i++)
        {
            cin>>c[i]>>h[i];
            v[c[i]][cnt[c[i]]]=h[i];
            v[h[i]][cnt[h[i]]]=c[i];
            cnt[c[i]]++;
            cnt[h[i]]++;

        }
        cin>>k1;
        for(int i=0;i<k1;i++)
        {
            cin>>a[i];
        }
        cin>>k2;
        for(int i=0;i<k2;i++)
        {
            cin>>b[i];
        }
        cout<<"B "<<b[0]<<endl;
        cin>>pos;
        for(int i=0;i<k1;i++)
        {
            if(a[i]==pos)
            {
                cout<<"C "<<pos<<endl;
                d=0;
            }
        }
        if(d)
        {
            dp[pos]=0;
        dfs(pos);
        pos2=0;
        for(int i=0;i<k1;i++)
        {
            if(dp[a[i]]<minn)
            {
                pos2=a[i];
                minn=dp[a[i]];
            }
        }
        cout<<"A "<<pos2<<endl;
        cin>>pos;
        for(int i=0;i<k2;i++)
        {
            if(b[i]==pos)
            {
                cout<<"C "<<pos2<<endl;
                dd=0;
            }
        }
        if(dd)
        {
            cout<<"C "<<-1<<endl;
        }

        }
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<cnt[i];j++)
            {
                v[i][j]=0;
            }
        }
        for(int i=0;i<=n;i++)
        {
            vis[i]=0;
            dp[i]=0;
            cnt[i]=0;
        }

    }
}