//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, typename F=function<R(T)> >
vector<R> fmap(F f, 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 mytl{

template<typename T>
T discrete_binary_search(function<bool(T)> f, T l, T r){
    if(!f(l)) return l;
    while(l < r){
        T pivot = (l+r)/2;
        if(!f(pivot)) r = pivot-1;
        else if(!f(pivot+1)) l = r = pivot;
        else l = pivot+1;
    }
    return l;
}

template<typename T>
T continuous_binary_search(function<bool(T)> f, T l, T r, need_int iterations){
    mytl::repeat(iterations,[&](){
        T pivot = (l+r)/2;
        if(f(pivot)) l = pivot;
        else r = pivot;
    });
    return l;
}
}

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>
istream& operator>>(istream& is, pair<P,Q> x){
    return is>>x.first>>x.second;
}

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, typename Container=vector<T>>
vector<T> readValues(ll n, istream& is=cin){
    vector<T> res;
    repeat(n, [&res](){
        res.push_back(read<T,Q...>());
    });
    return Container(res.begin(), res.end());
}

}

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 QP,
    template<typename> typename P,
    typename F=void(*)(pair<typename P<G>::Info, typename G::Node>)
>
typename G::template Container<typename G::Node, typename P<G>::Info> queue_graph_algorithm(
    G& g,
    vector<pair<typename P<G>::Info, typename G::Node> > sources,
    F new_node_callback=[](pair<typename P<G>::Info, typename G::Node>){})
{

    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;

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

        if(has_key(d, who)) continue;

        d[who] = info;

        new_node_callback(pair<Info, Node>(info, who));
        for(auto par : g.getEdges(who)) if(!has_key(d, par.second)){
            QueuePolicy::push(q, {Path::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 {from.first + e, from.second};
    }
};

template<typename G>
struct SimpleLengthAndLastNode{
    using Info = pair<typename G::Edge, typename G::Node>;
    static Info append(pair<Info, typename G::Node> from, typename G::Edge e, typename G::Node n){
        return {from.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->l);
        else partial = Op::reduce(left_child->build_from(getter), right_child->build_from(getter));
        return partial;
    }

};

struct Range1D{

    ll l, r;

    Range1D(ll l, ll r): l{l}, r{r} {}

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

        return other.inside(*this)
             ||(other.l <= l && l <= other.r)
             ||(other.l <= r && r <= other.r);
    }
};

}

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, typename F=function<R(T)> >
vector<R> fmap(F f, 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 mytl{

template<typename T>
T discrete_binary_search(function<bool(T)> f, T l, T r){
    if(!f(l)) return l;
    while(l < r){
        T pivot = (l+r)/2;
        if(!f(pivot)) r = pivot-1;
        else if(!f(pivot+1)) l = r = pivot;
        else l = pivot+1;
    }
    return l;
}

template<typename T>
T continuous_binary_search(function<bool(T)> f, T l, T r, need_int iterations){
    mytl::repeat(iterations,[&](){
        T pivot = (l+r)/2;
        if(f(pivot)) l = pivot;
        else r = pivot;
    });
    return l;
}
}

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>
istream& operator>>(istream& is, pair<P,Q> x){
    return is>>x.first>>x.second;
}

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, typename Container=vector<T>>
vector<T> readValues(ll n, istream& is=cin){
    vector<T> res;
    repeat(n, [&res](){
        res.push_back(read<T,Q...>());
    });
    return Container(res.begin(), res.end());
}

}

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 QP,
    template<typename> typename P,
    typename F=void(*)(pair<typename P<G>::Info, typename G::Node>)
>
typename G::template Container<typename G::Node, typename P<G>::Info> queue_graph_algorithm(
    G& g,
    vector<pair<typename P<G>::Info, typename G::Node> > sources,
    F new_node_callback=[](pair<typename P<G>::Info, typename G::Node>){})
{

    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;

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

        if(has_key(d, who)) continue;

        d[who] = info;

        new_node_callback(pair<Info, Node>(info, who));
        for(auto par : g.getEdges(who)) if(!has_key(d, par.second)){
            QueuePolicy::push(q, {Path::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 {from.first + e, from.second};
    }
};

template<typename G>
struct SimpleLengthAndLastNode{
    using Info = pair<typename G::Edge, typename G::Node>;
    static Info append(pair<Info, typename G::Node> from, typename G::Edge e, typename G::Node n){
        return {from.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{

    ll l, r;

    Range1D(ll l, ll r): l{l}, r{r} {}

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

        return other.inside(*this)
             ||(other.l <= l && l <= other.r)
             ||(other.l <= r && r <= other.r);
    }
};

}

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();
    }) ;
}


b'//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\xc3\x89
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>
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);})

}

namespace mytl{

template<typename T>
T discrete_binary_search(function<bool(T)> f, T l, T r){
    if(!f(l)) return l;
    while(l < r){
        T pivot = (l+r)/2;
        if(!f(pivot)) r = pivot-1;
        else if(!f(pivot+1)) l = r = pivot;
        else l = pivot+1;
    }
    return l;
}

template<typename T>
T continuous_binary_search(function<bool(T)> f, T l, T r, need_int iterations){
    mytl::repeat(iterations,[&](){
        T pivot = (l+r)/2;
        if(f(pivot)) l = pivot;
        else r = pivot;
    });
    return l;
}
}

namespace std{

template<typename T>
istream& operator>>(istream& is, 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>
istream& operator>>(istream& is, pair<P,Q> x){
    return is>>x.first>>x.second;
}

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, typename Container=vector<T>>
vector<T> readValues(ll n, istream& is=cin){
    vector<T> res;
    repeat(n, [&res](){
        res.push_back(read<T,Q...>());
    });
    return Container(res.begin(), res.end());
}

}

namespace mytl{

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

}

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{

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();
}

}

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{
    template<typename A, typename B>
    using Container = C<A,B>;
    using Edge = E;
    using Node = N;
    struct Arm{
        Edge edge;
        Node node;
    };

    Container<Node,  vector<Arm> > container;

    optional<ll> n;
    Container_Graph(ll n={}) : n{n}, container() {}

    void newEdge(Node u, Node v, Edge edge=Void()){
        container[u].push_back({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 : container){
                res.push_back(p.first);
            }
        }
        return res;

    }
    vector<Arm >& getEdges(Node node){
        return container[node];
    }
    vector<Node > getNeighbours(Node node){
        vector<Node> res;
        for(auto& arm : getEdges(node)){
            res.push_back(arm.node);
        }
        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 Path>
struct Reaching{
    typename Path<G>::Info info;
    typename G::Node node;
    bool operator<(const Reaching& other) const {
        return info > other.info;
    }
};

template<
    typename G,
    template<typename> typename QP,
    template<typename> typename P,
    typename F=void(*)(typename P<G>::Info, typename G::Node)
>
typename G::template Container<typename G::Node, typename P<G>::Info> queue_graph_algorithm(
    G& g,
    vector<Reaching<G,P> > sources,
    F new_node_callback=[](typename P<G>::Info, typename G::Node){})
{

    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 R = Reaching<G,P>;
    using QueuePolicy = QP<R>;
    using Queue = typename QueuePolicy::Queue;

    Queue q;
    for(R source : sources) QueuePolicy::push(q, source);
    typename G::template Container<Node, Info> d;
    while(!q.empty()){
        R akt = QueuePolicy::consume(q);

        if(has_key(d, akt.node)) continue;

        d[akt.node] = akt.info;

        new_node_callback(akt.info, akt.node);
        for(auto arm : g.getEdges(akt.node)) if(!has_key(d, arm.node)){
            QueuePolicy::push(q, {Path::append(akt.info, akt.node, arm.edge, arm.node), arm.node});
        }
    }
    return d;
}

template<
        typename G,
        template<typename> typename QP,
        template<typename> typename P,
        typename F=void(*)(typename P<G>::Info, typename G::Node)
>
typename G::template Container<typename G::Node, typename P<G>::Info> queue_graph_algorithm_from_single_source(
        G& g,
        typename P<G>::Info info,
        typename G::Node node,
        F new_node_callback=[](typename P<G>::Info, typename G::Node){})
{
    return queue_graph_algorithm<G,QP,P,F>(g, {{info,node}},new_node_callback);
}

template<typename T>
struct Priority{
    using Queue = priority_queue<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(Info old_info, typename G::Node old_node, typename G::Edge e, typename G::Node n){
        return old_info + e;
    }
};

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

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

template<typename G>
struct SimpleLengthAndLastNode{
    using Info = pair<typename G::Edge, typename G::Node>;
    static Info append(Info old_info, typename G::Node old_node, typename G::Edge e, typename G::Node n){
        return {old_info + 1, old_node};
    }
};

}

namespace mytl{

template<typename T, typename R, typename F=function<R(T)> >
vector<R> fmap(F f, 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, 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;
}
#define WATCH(x) cout << (#x) << " is " << (x) << endl
}

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->l);
        else partial = Op::reduce(left_child->build_from(getter), right_child->build_from(getter));
        return partial;
    }

};

struct Range1D{

    ll l, r;

    Range1D(ll l, ll r): l{l}, r{r} {}

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

        return other.inside(*this)
             ||(other.l <= l && l <= other.r)
             ||(other.l <= r && r <= other.r);
    }
};

}

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<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<typename T, T(*f)(T,T)>
struct Tracker : optional<T>{

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

    void update(T val){
        if(this->has_value()){
            optional<T>::operator=(f(this->value(), val));
        }
        else{
            optional<T>::operator=(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);}

}

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\n\nusing G = mytl::Container_Graph<ll, Void, mytl::AssocVector>;\n\n\n\n\nvoid processs(){\n    ll n;\n    cin>>n;\n    G g(n);\n    mytl::readEdgeList(g, n-1);\n\n        //cout<<"hh";\n    auto enyem_ = mytl::readValues<ll>(mytl::read<ll>());\n    set<ll> enyem(enyem_.begin(), enyem_.end());\n    auto ove_ = mytl::readValues<ll>(mytl::read<ll>());\n    set<ll> ove(ove_.begin(), ove_.end());\n\n    //cout<<enyem<<" "<<ove<<endl;\n    auto ask = [&](ll& ide, char tipus, ll ki) -> bool{\n        cout<<tipus<<" "<<ki<<endl;\n        ll got;\n        cin>>got;\n        if(tipus == \'A\' && mytl::has_key(ove, got)){\n            cout<<"C "<<ki<<endl;\n            return true;\n        }\n        if(tipus == \'B\' && mytl::has_key(enyem, got)){\n            cout<<"C "<<got<<endl;\n            return true;\n        }\n        ide = got;\n        return false;\n         \n    };\n\n\n    ll one_piece;\n    if(ask(one_piece, \'B\', *ove.begin())) return;\n     vector<pair<pair<ll,ll>, ll> > sour{{{0,-1}, *enyem.begin()}};\n    // cout<<sour<<endl;\n   auto tb = mytl::queue_graph_algorithm<G, mytl::AlgoComposer<mytl::FILO,mytl::SimpleLengthAndLastNode>::A >(g,sour);\n\n\n\n    while(!mytl::has_key(enyem, one_piece)){\n        one_piece = tb[one_piece].second;\n    }\n\n\n    ll dc;\n    if(ask(dc, \'A\', one_piece)) return;\n    else{\n        cout<<"C -1"<<endl;\n    }\n\n}\n\nMAIN main(){\n    ll T;\n    cin>>T;\n    mytl::repeat(T, [&](){\n        processs();\n    }) ;   \n}'


//STARTCOPY/n#include<bits/stdc++.h>/nusing namespace std;/n/nusing u_counter_type = unsigned int;/nusing need_int = int;/nusing counter_type = int;/nusing MAIN = int;/n#define int DontUseIntÉ/nusing ll = long long;/n/ntemplate<typename T>/nusing PairOf = pair<T,T>;/n/nusing Void = tuple<>;/n/nstruct BasicInitialization{/n    BasicInitialization(){/n        ios_base::sync_with_stdio(false);/n    }/n};/nBasicInitialization __basic_initialization__;/n//ENDCOPY
//STARTCOPY/nnamespace mytl{/n/n/ntemplate<typename T>/nstruct Lazy : optional<T>{/n/n    function<T()> f;/n/n    Lazy(function<T()> f) : f{f}, optional<T>() {};/n/n    T& value(){/n        if(!this->has_value()){/n            optional<T>::operator=(f());/n        }/n        return optional<T>::value();/n    }/n/n};/n/n#define LAZY(val, tipe) mytl::Lazy<tipe>([&](){return (val);})/n/n/n}/n//ENDCOPY
//STARTCOPY/nnamespace mytl{/n/ntemplate<typename T>/nT discrete_binary_search(function<bool(T)> f, T l, T r){/n    if(!f(l)) return l;/n    while(l < r){/n        T pivot = (l+r)/2;/n        if(!f(pivot)) r = pivot-1;/n        else if(!f(pivot+1)) l = r = pivot;/n        else l = pivot+1;/n    }/n    return l;/n}/n/ntemplate<typename T>/nT continuous_binary_search(function<bool(T)> f, T l, T r, need_int iterations){/n    mytl::repeat(iterations,[&](){/n        T pivot = (l+r)/2;/n        if(f(pivot)) l = pivot;/n        else r = pivot;/n    });/n    return l;/n}/n}/n//ENDCOPY
//STARTCOPY/n/nnamespace std{/n/ntemplate<typename T>/nistream& operator>>(istream& is, optional<T>& x){/n    if(!x.has_value()){/n        T x_;/n        is>>x_;/n        x = x_;/n    }/n    return is;/n}/n/nistream& operator>>(istream& is, Void& x){/n    return is;/n}/n/ntemplate<typename P, typename Q>/nistream& operator>>(istream& is, pair<P,Q> x){/n    return is>>x.first>>x.second;/n}/n/n/ntemplate<typename P, typename Q>/nostream& operator<<(ostream& os, const pair<P,Q>& x){/n    os<<"("<<x.first<<", "<<x.second<<")";/n    return os;/n}/n/ntemplate<typename T, template<typename, typename...> typename Container>/nostream& operator<<(ostream& os, const Container<T>& x){/n    os<<"{";/n    bool first = true;/n    for(const auto& elem : x){/n        if(!first) os<<", ";/n        os<<elem;/n        first = false;/n    }/n    os<<"}";/n    return os;/n}/n/n}/n/nnamespace mytl{/n/ntemplate<typename T, typename P=T>/nT read(istream& is=cin){/n    P a;/n    is>>a;/n    return T(a);/n}/n/ntemplate<typename T, typename P, typename Q>/nT read(istream& is=cin){/n    P a;/n    Q b;/n    is>>a>>b;/n    return T(a,b);/n}/n/ntemplate<typename T, typename P, typename Q, typename R>/nT read(istream& is=cin){/n    P a;/n    Q b;/n    R c;/n    is>>a>>b>>c;/n    return T(a,b,c);/n}/n/n/ntemplate<typename T, typename... Q, typename Container=vector<T>>/nvector<T> readValues(ll n, istream& is=cin){/n    vector<T> res;/n    repeat(n, [&res](){/n        res.push_back(read<T,Q...>());/n    });/n    return Container(res.begin(), res.end());/n}/n/n}/n/n/nnamespace mytl{/n/n/ntemplate<typename T>/nvoid print(const T& x, ostream& os=cout){/n    os<<x;/n}/n/n}/n//ENDCOPY
//STARTCOPY/nnamespace mytl{/n    template<ll MOD>/n    struct TSModulo{/n    private:/n        ll val;/n/n    public:/n        static TSModulo inverse(TSModulo x){// asserting MOD is prime/n            return power(x, MOD-2);/n        };/n        TSModulo(ll initVal) : val{(MOD + initVal%MOD)%MOD} {};/n        TSModulo() : TSModulo(0) {}/n        TSModulo& operator=(const TSModulo&) = default;/n/n        ll get() const{ // no type cast operator to prevent accidentally turning into ordinary number/n            return val;/n        }/n/n        //Unary operators/n        TSModulo operator-() const{/n            return TSModulo(-val);/n        };/n        TSModulo operator+() const{/n            return TSModulo(+val);/n        };/n/n        //Binary operators on ordinary numbers/n        TSModulo operator-(const ll& operand) const{/n            return TSModulo(val-operand);/n        };/n        TSModulo operator+(const ll& operand) const{/n            return TSModulo(val+operand);/n        };/n        TSModulo operator*(const ll& operand) const{/n            return TSModulo(val*operand);/n        };/n        TSModulo operator/(const ll& operand) const{ //asserting MOD is prime/n            return TSModulo(inverse(operand) * val);/n        };/n/n        //Binary operators on Modulo/n        TSModulo operator-(const TSModulo& operand) const{/n            return TSModulo(val-operand.get());/n        };/n        TSModulo operator+(const TSModulo& operand) const{/n            return TSModulo(val+operand.get());/n        };/n        TSModulo operator*(const TSModulo& operand) const{/n            return TSModulo(val*operand.get());/n        };/n        TSModulo operator/(const TSModulo& operand) const{ //asserting MOD is prime/n            return TSModulo(val * inverse(operand));/n        };/n    };/n/n    using Mod107 = TSModulo<1000000007LL>;/n/n    template<ll MOD>/n    ostream& operator<<(ostream& os, TSModulo<MOD> x){/n        return os<<"("<<x.get()<<"%"<<MOD<<")";/n    }/n/n/n}/n//ENDCOPY
//STARTCOPY/nnamespace mytl{/n/ntemplate<typename T>/nstruct LazyVector : vector<T>{/n    typename vector<T>::reference operator[](counter_type i){/n        if(i >= this->size()) this->resize(i+1);/n        return vector<T>::operator[](i);/n    }/n};/n/ntemplate<typename K, typename T>/nstruct AssocVector : LazyVector<T>{/n    LazyVector<bool> exists;/n    typename vector<T>::reference operator[](counter_type i){/n        exists[i] = true;/n        return LazyVector<T>::operator[](i);/n    }/n    typename vector<T>::iterator find(counter_type i){/n        if(!exists[i]) return this->end();/n        else return this->begin() + i;/n    }/n};/n/ntemplate<template<typename, typename, typename...> typename Container, typename Key, typename Value>/nbool has_key(Container<Key, Value>& container, Key key){/n    return container.find(key) != container.end();/n}/n/n}/n//ENDCOPY
//STARTCOPY/nnamespace mytl{/n    struct Modulo{/n        static ll global_mod;/n    private:/n        ll val;/n    public:/n        const ll MOD;/n        Modulo(ll initMOD, ll initVal) : MOD{initMOD}, val{initVal} {/n            val %= MOD;/n            if(val < 0) val += MOD;/n        };/n        Modulo() : Modulo(global_mod, 0) {};/n/n        static Modulo inverse(Modulo x){// asserting MOD is prime/n            return power(x, x.MOD-2, x.unit());/n        };/n        Modulo unit() const{/n            return Modulo(MOD, 1);/n        }/n        Modulo& operator=(const Modulo& operand){/n            val = operand.val;/n            return *this;/n        };/n/n        ll get() const{ // no type cast operator to prevent accidentally turning into ordinary number/n            return val;/n        }/n/n        //Unary operators/n        Modulo operator-() const{/n            return Modulo(MOD, -val);/n        };/n        Modulo operator+() const{/n            return Modulo(MOD, +val);/n        };/n/n        //Binary operators on ordinary numbers/n        Modulo operator-(const ll& operand) const{/n            return Modulo(MOD, val-operand);/n        };/n        Modulo operator+(const ll& operand) const{/n            return Modulo(MOD, val+operand);/n        };/n        Modulo operator*(const ll& operand) const{/n            return Modulo(MOD, val*operand);/n        };/n        Modulo operator/(const ll& operand) const{ //asserting MOD is prime/n            return Modulo(MOD, val * inverse(Modulo(MOD, operand)).get());/n        };/n/n        //Binary operators on Modulo/n        Modulo operator-(const Modulo& operand) const{/n            return Modulo(MOD, val-operand.get());/n        };/n        Modulo operator+(const Modulo& operand) const{/n            return Modulo(MOD, val+operand.get());/n        };/n        Modulo operator*(const Modulo& operand) const{/n            return Modulo(MOD, val*operand.get());/n        };/n        Modulo operator/(const Modulo& operand) const{ //asserting MOD is prime/n            return Modulo(MOD, val * inverse(operand).get());/n        };/n/n    };/n/n    ll Modulo::global_mod = 1000000007LL;/n/n    Modulo mod107(ll x){/n        return Modulo(1000000007LL, x);/n    }/n    ostream& operator<<(ostream& os, Modulo x){/n        return os<<"("<<x.get()<<"%"<<x.MOD<<")";/n    }/n/n/n}/n//ENDCOPY
//STARTCOPY/nnamespace mytl {/n/ntemplate<class T>/nstruct Resetter;/n/ntemplate<class T>/nResetter<T>* global_resetter = new Resetter<T>;/n/ntemplate<class T>/nstruct Resetter {/n/n    using State = pair<counter_type, T>;/n/n    State* state = new State{0, T()};/n/n    Resetter(){}/n    Resetter(T value){/n        state = new State{0, value};/n    }/n/n    void activate(){/n        global_resetter<T> = this;/n    }/n/n    void reset(T value){/n        *state = State{state->first+1, value};/n    }/n/n    struct Variable{/n/n        State state;/n        State& parent = *global_resetter<T>->state;/n/n        Variable() : state{*global_resetter<T>->state} {}/n        Variable(T value) : state{global_resetter<T>->state->first, value} {}/n        Variable(State st) : state{st} {}/n        Variable(T value, State& parent) : state{parent->first, value} {};/n/n        bool fresh(){/n            return state.first >= parent.first;/n        }/n/n        void overwrite(){/n            state = parent;/n        }/n/n        bool refresh(){/n            if(!fresh()) overwrite();/n        }/n/n        T get(){/n            refresh();/n            return state.second;/n        }/n/n        void survive(){/n            state.first = parent.first;/n        }/n/n        void operator=(T new_value){/n            state.second = new_value;/n            survive();/n        }/n/n    };/n/n};/n}/n//ENDCOPY
//STARTCOPY/nnamespace mytl{/n/n/n/ntemplate<typename N, typename E, template<typename, typename, typename...> typename C>/nstruct Container_Graph{/n    template<typename A, typename B>/n    using Container = C<A,B>;/n    using Edge = E;/n    using Node = N;/n    struct Arm{/n        Edge edge;/n        Node node;/n    };/n/n    Container<Node,  vector<Arm> > container;/n/n    optional<ll> n;/n    Container_Graph(ll n={}) : n{n}, container() {}/n/n    void newEdge(Node u, Node v, Edge edge=Void()){/n        container[u].push_back({edge, v});/n    }/n    vector<Node> getNodes(){/n        vector<Node> res;/n        if(n.has_value()){/n            for(ll i=1; i<=n.value(); i++) res.push_back(i);/n        }/n        else{/n            for(auto& p : container){/n                res.push_back(p.first);/n            }/n        }/n        return res;/n/n    }/n    vector<Arm >& getEdges(Node node){/n        return container[node];/n    }/n    vector<Node > getNeighbours(Node node){/n        vector<Node> res;/n        for(auto& arm : getEdges(node)){/n            res.push_back(arm.node);/n        }/n        return res;/n    }/n/n};/n/nusing NormalSimpleGraph = Container_Graph<ll, Void, AssocVector>;/n/ntemplate<typename G>/nvoid readNeighbourList(G& g, ll indexing=1){/n    for(ll i : forrange(g.n.size(), indexing)){/n        for(ll neig : readValues<ll>(read<ll>())){/n            g.new_edge(i, neig);/n        }/n    }/n}/n/ntemplate<typename G>/nvoid readEdgeList(G& g, ll m, bool bidirectional=true){/n    using Node = typename G::Node;/n    using Edge = typename G::Edge;/n    for(auto elem : readValues<tuple<Node, Node, Edge>, Node, Node, Edge >(m)){/n        Node u, v;/n        Edge edge;/n        tie(u, v, edge) = elem;/n        g.newEdge(u,v,edge);/n        if(bidirectional) g.newEdge(v, u, edge);/n    }/n}/n/ntemplate<typename G, template<typename> typename Path>/nstruct Reaching{/n    typename Path<G>::Info info;/n    typename G::Node node;/n    bool operator<(const Reaching& other) const {/n        return info > other.info;/n    }/n};/n/ntemplate</n    typename G,/n    template<typename> typename QP,/n    template<typename> typename P,/n    typename F=void(*)(typename P<G>::Info, typename G::Node)/n>/ntypename G::template Container<typename G::Node, typename P<G>::Info> queue_graph_algorithm(/n    G& g,/n    vector<Reaching<G,P> > sources,/n    F new_node_callback=[](typename P<G>::Info, typename G::Node){})/n{/n/n    using Path = P<G>;/n    using Edge = typename G::Edge;/n    using Node = typename G::Node;/n    using Info = typename Path::Info;/n    //using Option = pair<Info, Node>;/n    using R = Reaching<G,P>;/n    using QueuePolicy = QP<R>;/n    using Queue = typename QueuePolicy::Queue;/n/n    Queue q;/n    for(R source : sources) QueuePolicy::push(q, source);/n    typename G::template Container<Node, Info> d;/n    while(!q.empty()){/n        R akt = QueuePolicy::consume(q);/n/n        if(has_key(d, akt.node)) continue;/n/n        d[akt.node] = akt.info;/n/n        new_node_callback(akt.info, akt.node);/n        for(auto arm : g.getEdges(akt.node)) if(!has_key(d, arm.node)){/n            QueuePolicy::push(q, {Path::append(akt.info, akt.node, arm.edge, arm.node), arm.node});/n        }/n    }/n    return d;/n}/n/ntemplate</n        typename G,/n        template<typename> typename QP,/n        template<typename> typename P,/n        typename F=void(*)(typename P<G>::Info, typename G::Node)/n>/ntypename G::template Container<typename G::Node, typename P<G>::Info> queue_graph_algorithm_from_single_source(/n        G& g,/n        typename P<G>::Info info,/n        typename G::Node node,/n        F new_node_callback=[](typename P<G>::Info, typename G::Node){})/n{/n    return queue_graph_algorithm<G,QP,P,F>(g, {{info,node}},new_node_callback);/n}/n/n/n/ntemplate<typename T>/nstruct Priority{/n    using Queue = priority_queue<T>;/n    static T consume(Queue& q){/n        auto res = q.top();/n        q.pop();/n        return res;/n    }/n    static void push(Queue& q, T new_option){/n        q.push(new_option);/n    }/n};/n/n/ntemplate<typename T>/nstruct FIFO{/n    using Queue = queue<T>;/n    static T consume(Queue& q){/n        auto res = q.front();/n        q.pop();/n        return res;/n    }/n    static void push(Queue& q, T new_option){/n        q.push(new_option);/n    }/n};/n/ntemplate<typename T>/nstruct FILO{/n    using Queue = stack<T>;/n    static T consume(Queue& q){/n        auto res = q.top();/n        q.pop();/n        return res;/n    }/n    static void push(Queue& q, T new_option){/n        q.pop();/n    }/n};/n/ntemplate<typename G>/nstruct JustLength{/n    using Info = typename G::Edge;/n    static Info append(Info old_info, typename G::Node old_node, typename G::Edge e, typename G::Node n){/n        return old_info + e;/n    }/n};/n/ntemplate<typename G>/nstruct SimpleJustLength{/n    using Info = ll;/n    static Info append(Info old_info, typename G::Node old_node, typename G::Edge e, typename G::Node n){/n        return old_info + 1;/n    }/n};/n/n/ntemplate<typename G>/nstruct LengthAndLastNode{/n    using Info = pair<ll, typename G::Node>;/n    static Info append(Info old_info, typename G::Node old_node, typename G::Edge e, typename G::Node n){/n        return {old_info + e, old_node};/n    }/n};/n/ntemplate<typename G>/nstruct SimpleLengthAndLastNode{/n    using Info = pair<typename G::Edge, typename G::Node>;/n    static Info append(Info old_info, typename G::Node old_node, typename G::Edge e, typename G::Node n){/n        return {old_info + 1, old_node};/n    }/n};/n/n}/n//ENDCOPY
//STARTCOPY/nnamespace mytl{/n/ntemplate<typename T, typename R, typename F=function<R(T)> >/nvector<R> fmap(F f, const vector<T>& t){/n    vector<R> res;/n    for(auto elem : t) res.push_back(f(elem));/n    return res;/n}/n/ntemplate<typename T>/nvector<T> forrange(T n, T from){/n    vector<T> res(n);/n    iota(res.begin(), res.end(), from);/n    return res;/n}/n/ntemplate<typename F>/nvoid repeat(need_int n, const F& callback){/n    for(need_int _ : forrange(n,0)) callback();/n}/n/n/ntemplate<typename T, template<typename, typename...> typename Container>/nvector<PairOf<T&> > adjecent_pairs(Container<T>& c){/n    vector<PairOf<T&> > res;/n    optional<T*> prev_elem;/n    for(auto& elem : c){/n        if(prev_elem.has_value()){/n            res.push_back({*prev_elem.value(), elem});/n        }/n        prev_elem = &elem;/n    }/n    return res;/n}/n#define WATCH(x) cout << (#x) << " is " << (x) << endl/n}/n//ENDCOPY
//STARTCOPY/nnamespace mytl{/n/nstruct Point{/n    ll x, y;/n/n    Point(ll x, ll y) : x{x}, y{y} {};/n    Point(pair<ll,ll> initPair) : x{initPair.first}, y{initPair.second} {};/n/n    pair<ll,ll> getPair(){//not introducing type cast operator for safety/n        return {x,y};/n    }/n/n    //Unary operators/n    Point operator-() const{/n        return {-x, -y};/n    }/n    Point operator+() const{/n        return {x,y};/n    }/n/n    static ll sgn(ll x){/n        return (x > 0) - (x < 0);/n    }/n/n    //Binary operators on ordinary numbers/n    Point operator*(const ll& operand) const{/n        return {x*operand, y*operand};/n    }/n/n    //Binary operators on Point itself/n    Point operator+(const Point& operand) const{/n        return {x+operand.x, y+operand.y};/n    }/n    Point operator-(const Point& operand) const{/n        return {x-operand.x, y-operand.y};/n    }/n/n    ll operator*(const Point& operand){ //vectorial product/n        return x*operand.y - y*operand.x;/n    }/n/n    ll direction(const Point& a, const Point& b) const{/n        return sgn((a - *this) * (b - *this));/n    };/n};/n/nll distance_squared(const Point& a, const Point& b){/n    return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);/n}/n/ndouble distance(const Point& a, const Point& b){/n    return sqrt(distance_squared(a, b));/n}/n/nll cartesian_distance(const Point& a, const Point& b){/n    return abs(a.x - b.x) + abs(a.y - b.y);/n}/n/ntypedef vector<Point> Poly;/n/nbool inside(const Poly& poly, const Point& point, bool strict){ //assuming Poly is weakly convex/n    ll prevdir = -2;/n    for(ll i=0; i<poly.size(); i++){/n        ll nexdindex = (i+1)%poly.size();/n        ll dir = poly[i].direction(poly[nexdindex], point);/n        if(dir == 0){/n            if(strict) return false;/n        }/n        else{/n            if(dir != prevdir && prevdir != -2) return false;/n            prevdir = dir;/n        }/n/n    }/n    return true;/n}/n/n}/n//ENDCOPY
//STARTCOPY/nnamespace mytl{/ntemplate<class Op>/nstruct Node : Op::Range{/n    using Range = typename Op::Range;/n    using T = typename Op::T;/n    using Change = typename Op::Change;/n    using Range::singleton;/n    using Range::inside;/n    using Range::intersect;/n    using Range::leftHalf;/n    using Range::rightHalf;/n/n    Node *left_child=NULL, *right_child=NULL;/n/n    T partial;/n    Change pending = Op::identity();/n/n    Node(Range range) : Range(range), partial{Op::initial(range)} {};/n/n    T query(Range range, Change change){/n        return query_(range, change).first;/n    }/n/n    void add(Change change){/n        pending = Op::push(pending, change);/n    }/n/n    void prepare(){/n        if(!singleton()){/n            if(left_child == NULL) left_child = (new Node(leftHalf()));/n            if(right_child == NULL) right_child = (new Node(rightHalf()));/n            left_child->add(pending);/n            right_child->add(pending);/n        }/n        partial = Op::apply(*this, partial, pending);/n        pending = Op::identity();/n    }/n/n    pair<T,T> query_(Range range, Change change){/n        //cout<<range<<" "<<*this<<endl;/n        prepare();/n        if(inside(range)){/n            add(change);/n            prepare();/n            return {partial, Op::zero()};/n        }/n        if(!intersect(range)){/n            //cout<<"n"<<range<<" "<<*this<<endl;/n            return {Op::zero(), partial};/n        }/n/n        auto from_left = left_child->query_(range, change);/n        auto from_right = right_child->query_(range, change);/n        //cout<<from_right.first<<endl;/n        auto needed = Op::reduce(from_left.first, from_right.first), rest = Op::reduce(from_left.second, from_right.second);/n        partial = Op::reduce(needed, rest);/n        return {needed, rest};/n    }/n/n    T build_from(const function<T(ll)>& getter){/n        prepare();/n        pending = Op::identity();/n        if(singleton()) partial = getter(this->l);/n        else partial = Op::reduce(left_child->build_from(getter), right_child->build_from(getter));/n        return partial;/n    }/n/n};/n/nstruct Range1D{/n/n    ll l, r;/n/n    Range1D(ll l, ll r): l{l}, r{r} {}/n/n    ll span() const {/n        return r-l+1;/n    }/n    bool singleton() const {/n        return span() == 1;/n    }/n    Range1D leftHalf() const {/n        return Range1D(l, (l+r)/2);/n    }/n    Range1D rightHalf() const {/n        return Range1D((l + r)/2 + 1, r);/n    }/n    bool inside(const Range1D& other) const {/n        return other.l <= l && r <= other.r;/n    }/n    bool intersect(const Range1D& other) const {/n/n        return other.inside(*this)/n             ||(other.l <= l && l <= other.r)/n             ||(other.l <= r && r <= other.r);/n    }/n};/n/n/n}/n/nnamespace mytl{/ntemplate<typename T_>/nstruct Add_Sum{/n    using Range = Range1D;/n    using T = T_;/n    using Change = T_;/n/n    static Change identity(){/n        return 0;/n    }/n/n    static T zero(){/n        return 0;/n    }/n/n    static T initial(Range r){/n        return zero();/n    }/n/n    static T reduce(T a, T b){/n        return a + b;/n    }/n/n    static T apply(Range r, T a, Change c){/n        return a + r.span()*c;/n    }/n/n    static Change push(Change a, Change b){/n        return a + b;/n    }/n};/n/ntemplate<typename T_>/nstruct Multiply_Sum{/n    using Range = Range1D;/n    using T = T_;/n    using Change = T_;/n/n    static Change identity(){/n        return 1;/n    }/n/n    static T zero(){/n        return 0;/n    }/n/n    static T initial(Range r){/n        return r.span()*1;/n    }/n/n    static T reduce(T a, T b){/n        return a + b;/n    }/n/n    static T apply(Range r, T a, Change c){/n        return a*c;/n    }/n/n    static Change push(Change a, Change b){/n        return a*b;/n    }/n};/n/n/n}/n/nnamespace mytl{/n/*/nstruct Custom_Op{/n    using Range = _;/n    using T = _;/n    using Change = _;/n/n    static Change identity(){/n        return _;/n    }/n/n    static T zero(){/n        return _;/n    }/n/n    static T initial(Range r){/n        return _;/n    }/n/n    static T reduce(T a, T b){/n        return _;/n    }/n/n    static T apply(Range r, T a, Change c){/n        return _;/n    }/n/n    static Change push(Change a, Change b){/n        return _;/n    }/n/n};/n*//n/n}/n//ENDCOPY
//STARTCOPY/nnamespace mytl{/ntemplate<typename T>/nT power(T base, ll exponential, T unit=1){/n    T res = unit;/n    while(exponential > 0){/n        if(exponential%2 == 1) res = res * base;/n        base = base * base;/n        exponential = exponential / 2;/n    }/n    return res;/n}/n}/n//ENDCOPY
//STARTCOPY/nnamespace mytl{/n/ntemplate<typename T, T(*f)(T,T)>/nstruct Tracker : optional<T>{/n/n    Tracker() : optional<T>() {};/n/n    void update(T val){/n        if(this->has_value()){/n            optional<T>::operator=(f(this->value(), val));/n        }/n        else{/n            optional<T>::operator=(val);/n        }/n    }/n};/n/ntemplate<typename T>/nT min(T a, T b){return std::min(a,b);}/ntemplate<typename T>/nT max(T a, T b){return std::max(a,b);}/ntemplate<typename T>/nT __gcd(T a, T b){return std::__gcd(a,b);}/n/n}/n//ENDCOPY
//STARTCOPY/nnamespace mytl{/n/ntemplate <template<typename, typename, typename...> typename C, typename Arg, typename R>/nfunction<R (Arg)> memoize(R (*fn)(Arg)) {/n    C<Arg, optional<R> > table;/n    return [fn, table](Arg arg) mutable -> R {/n        optional<R>& res = table[arg];/n        if(!res.has_value()){/n            res = fn(arg);/n        }/n        return res.value();/n    };/n}/n/n/n}/n//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();
    }) ;
}