/* -*- coding: utf-8 -*- * * 2307.cc: No.2307 [Cherry 5 th Tune *] Cool 46 - yukicoder */ #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 200000; const int MAX_M = 200000; enum { R, B }; const char css[2][8] = {"Red", "Blue"}; /* typedef */ typedef queue qi; typedef pair pii; typedef vector vpii; /* global variables */ int as[MAX_N], bs[MAX_M]; /* subroutines */ /* main */ int main() { int tn; scanf("%d", &tn); while (tn--) { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", as + i); for (int i = 0; i < m; i++) scanf("%d", bs + i); sort(as, as + n); sort(bs, bs + m); qi rv, bv, ev; int ai = 0, bi = 0; while (ai < n && bi < m) { if (as[ai] < bs[bi]) rv.push(as[ai++]); else if (as[ai] > bs[bi]) bv.push(bs[bi++]); else ev.push(as[ai++]), bi++; } while (ai < n) rv.push(as[ai++]); while (bi < m) bv.push(bs[bi++]); if (! rv.empty() && ! bv.empty() && ev.empty()) { puts("No"); continue; } vpii ans; int c = (! rv.empty()) ? R : B; while (! rv.empty() || ! bv.empty() || ! ev.empty()) { while (c == R && ! rv.empty()) ans.push_back({R, rv.front()}), rv.pop(); while (c == B && ! bv.empty()) ans.push_back({B, bv.front()}), bv.pop(); if (! ev.empty()) { int e = ev.front(); ev.pop(); ans.push_back({c, e}); c ^= 1; ans.push_back({c, e}); } } puts("Yes"); for (auto [c, e]: ans) printf("%s %d\n", css[c], e); } return 0; }