#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } struct UnionFind { vector data; UnionFind(int size) : data(size, -1) {} bool unionSet(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; template class Compress{ public: vector data; int offset; Compress(vector data_, int offset=0): offset(offset){ data = data_; sort(begin(data), end(data)); data.erase(unique(begin(data), end(data)), end(data)); }; int operator[](T x) { auto p = lower_bound(data.begin(), data.end(), x); assert(x == *p); return offset+(p-data.begin()); } T inv(int x){ return data[x-offset]; } int size(){ return data.size(); } }; void solve(){ int n, m; cin >> n >> m; vector a(n), b(m); for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < m; i++) cin >> b[i]; if(n == 0){ cout << "Yes" << endl; for(int x: b) cout << "Red " << x << '\n'; return; } if(m == 0){ cout << "Yes" << endl; for(int x: a) cout << "Blue " << x << '\n'; return; } set st_a; for(int x: a) st_a.insert(x); set st_ab; for(int x: b){ if(st_a.count(x)) st_ab.insert(x); } if(st_ab.size() == 0){ cout << "No" << endl; return; } vector only_a, only_b; for(int x: a){ if(st_ab.count(x) == 0) only_a.push_back(x); } for(int x: b){ if(st_ab.count(x) == 0) only_b.push_back(x); } bool red = true; cout << "Yes" << endl; for(int x: only_a) cout << "RED " << x << '\n'; bool first = true; for(int x: st_ab){ if(red){ cout << "RED " << x << '\n'; cout << "BLUE " << x << '\n'; }else{ cout << "BLUE " << x << '\n'; cout << "RED " << x << '\n'; } if(first){ for(int x: only_b) cout << "BLUE " << x << '\n'; } red = !red; first = false; } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int t; cin >> t; while(t--) solve(); }