#pragma GCC optimize("Ofast") #include using namespace std; typedef long long int ll; typedef unsigned long long int ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } inline double time() { return static_cast(chrono::duration_cast(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9; } void slv() { 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 (m == 0) { cout << "Yes" << "\n"; for (int i = 0; i < n; ++i) { cout << "Red" << " " << a[i] << "\n"; } return; } if (n == 0) { cout << "Yes" << "\n"; for (int i = 0; i < m; ++i) { cout << "Blue" << " " << b[i] << "\n"; } return; } vector R,B,RB; set st; for (int i = 0; i < n; ++i) { st.insert(a[i]); } for (int i = 0; i < m; ++i) { if (st.find(b[i]) != st.end()) { RB.push_back(b[i]); st.erase(b[i]); } else { B.push_back(b[i]); } } for (int i : st) { R.push_back(i); } if (RB.size() == 0) { cout << "No" << "\n"; return; } cout << "Yes" << "\n"; for (int i: R) { cout << "Red " << i << "\n"; } cout << "Red " << RB[0] << "\n"; cout << "Blue " << RB[0] << "\n"; for (int i: B) { cout << "Blue " << i << "\n"; } for (int i = 1; i < RB.size(); ++i) { if (i%2 == 1) { cout << "Blue " << RB[i] << "\n"; cout << "Red " << RB[i] << "\n"; } else { cout << "Red " << RB[i] << "\n"; cout << "Blue " << RB[i] << "\n"; } } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int q; cin >> q; while (q--) { slv(); } }