// #define _GLIBCXX_DEBUG #include using namespace std; #include using namespace atcoder; using ll = long long; #define rep(i,n) for (ll i = 0; i < (n); ++i) using vl = vector; using vvl = vector; using P = pair; #define pb push_back #define int long long #define double long double #define INF (ll) 3e18 // Ctrl + Shift + B コンパイル // Ctrl + C 中断 // ./m 実行 void solve(){ int n, m; cin >> n >> m; vl a(n); vl b(m); rep(i,n) cin >> a[i]; rep(i,m) cin >> b[i]; if (n == 0 || m == 0){ cout << "Yes" << endl; for(auto x : a) cout << "Red " << x << endl; for(auto x : b) cout << "Blue " << x << endl; return; } // abが共に等しいとき、移動することができる // a同士、b同士は相異なるため、同じ数値のペアだけを考えればよい set amp; set bmp; rep(i,n) amp.insert(a[i]); rep(i,m) bmp.insert(b[i]); vl ab; for(auto i : amp) if (bmp.count(i)) { ab.push_back(i); } if (ab.size() == 0) cout << "No" << endl; else { cout << "Yes" << endl; // 具体的な解答例を出力する for(auto i : amp) if (!bmp.count(i)) { cout << "Red " << i << endl; } cout << "Red " << ab[0] << endl; cout << "Blue " << ab[0] << endl; for(auto i : bmp) if (!amp.count(i)) { cout << "Blue " << i << endl; } bool c = 0; auto teban = [&]() -> string { c ^= 1; if (c) return "Blue "; if (!c) return "Red "; }; for(int i = 1; i < ab.size(); ++i){ cout << teban() << ab[i] << endl; cout << teban() << ab[i] << endl; } } } signed main(){ int t; cin >> t; rep(_,t){ solve(); } }