#include #define int long long #define len(a) (int)a.size() using namespace std; int check(int n, int na, int nb, int nc, vector a, vector b, vector c, int S) { if (len(a) > na || len(b) > nb || len(c) > nc) return 0; int A = accumulate(a.begin(), a.end(), 0LL); int B = accumulate(b.begin(), b.end(), 0LL); int C = accumulate(c.begin(), c.end(), 0LL); multiset sa, sb, sc; for (int i = 3; i < 3 + nc - len(c); i++) sc.insert(x[i]); for (int i = 3 + nc - len(c); i < 3 + nc - len(c) + na - len(a);i++) sa.insert(x[i]); for (int i = 3 + nc - len(c) + na - len(a); i < n; i++) sb.insert(x[i]); assert(len(sa) + len(a) == na); assert(len(sb) + len(b) == nb); assert(len(sc) + len(c) == nc); for (auto t : sa) A += t; for (auto t : sb) B += t; for (auto t : sc) C += t; vector order = {0, 1, 2}; if (A > C && A > B) { swap(A, C); swap(sa, sc); swap(a, c); swap(na, nc); order = {2, 1, 0}; } else if (B > C && B > A) { swap(B, C); swap(sb, sc); swap(b, c); swap(nb, nc); order = {0, 2, 1}; } auto bad = [&]() { return C >= A + B; }; vector sta, stb, stc; for (auto i : sc) stc.push_back(i); while (bad()) { // cout << A << ' ' << B << ' ' << C << endl; // try change if (!stc.empty()) { int nc = stc.back(); stc.pop_back(); auto it = sa.lower_bound(nc); if (it != sa.begin()) { it--; int na = *it; if (2 * (A - na + nc) < S) { sa.erase(sa.find(na)); sc.erase(sc.find(nc)); sa.insert(nc); sc.insert(na); A = A - na + nc; C = C - nc + na; stc.push_back(na); sta.push_back(nc); continue; } } it = sb.lower_bound(nc); if (it != sb.begin()) { it--; int nb = *it; if (2 * (B - nb + nc) < S) { sb.erase(sb.find(nb)); sc.erase(sc.find(nc)); sb.insert(nc); sc.insert(nb); B = B - nb + nc; C = C - nc + nb; stc.push_back(nb); stb.push_back(nc); continue; } } } if (!sta.empty()) { int na = sta.back(); sta.pop_back(); auto it = sc.upper_bound(na); if (it != sc.end()) { int nc = *it; if (2 * (A - na + nc) < S) { sa.erase(sa.find(na)); sc.erase(sc.find(nc)); sa.insert(nc); sc.insert(na); A = A - na + nc; C = C - nc + na; stc.push_back(na); sta.push_back(nc); continue; } } } if (!stb.empty()) { int nb = stb.back(); stb.pop_back(); auto it = sc.upper_bound(nb); if (it != sc.end()) { int nb = *it; if (2 * (B - nb + nc) < S) { sb.erase(sb.find(nb)); sc.erase(sc.find(nc)); sb.insert(nc); sc.insert(nb); B = B - nb + nc; C = C - nc + nb; stc.push_back(nb); stb.push_back(nc); continue; } } } // can't do anything return 0; } cout << "YES\n"; for (auto i : order) { multiset ss; vector s; if (i == 0) s = a, ss = sa; else if (i == 1) s = b, ss = sb; else if (i == 2) s = c, ss = sc; for (auto& j : ss) cout << j << ' '; for (auto& j : s) cout << j << ' '; cout << '\n'; } return 1; }; int slv(int n, int na, int nb, int nc, const vector& x) { vector a, b, c; int S = accumulate(x.begin(), x.end(), 0LL); for (int i1 = 0; i1 < 3; i1++) for (int i2 = 0; i2 < 3; i2++) for (int i3 = 0; i3 < 3; i3++) { a.clear(), b.clear(), c.clear(); if (i1 == 0) a.push_back(x[0]); if (i1 == 1) b.push_back(x[0]); if (i1 == 2) c.push_back(x[0]); if (i2 == 0) a.push_back(x[1]); if (i2 == 1) b.push_back(x[1]); if (i2 == 2) c.push_back(x[1]); if (i3 == 0) a.push_back(x[2]); if (i3 == 1) b.push_back(x[2]); if (i3 == 2) c.push_back(x[2]); if (check(n, na, nb, nc, a, b, c, S)) { return 1; } } return 0; } void solve() { int n; cin >> n; int na, nb, nc; cin >> na >> nb >> nc; vector x(n); for (auto &i : x) cin >> i; sort(x.begin(), x.end()); reverse(x.begin(), x.end()); int z = slv(n, na, nb, nc, x, {0, 1, 2}); if (!z) { cout << "NO\n"; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) solve(); return 0; }