#include using namespace std; #define FOR(i, a, b) for(int i = (a); i < (b); i++) #define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--) #define SZ(a) int(a.size()) #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair #define F first #define S second typedef long long LL; typedef vector VI; typedef pair PII; typedef double db; pair ok(vector& sum, LL tot) { int idxMax = max_element(ALL(sum)) - sum.begin(); return {2 * sum[idxMax] < tot, idxMax}; } void print(const vector& ans) { cout << "YES\n"; FOR(i, 0, 3) { FOR(j, 0, SZ(ans[i])) { if (j) cout << " "; cout << ans[i][j]; } cout << "\n"; } } void sw(vector& ans, vector& sum, int i1, int j1, int i2, int j2) { sum[i1] -= ans[i1][j1]; sum[i2] -= ans[i2][j2]; swap(ans[i1][j1], ans[i2][j2]); sum[i1] += ans[i1][j1]; sum[i2] += ans[i2][j2]; } void solve() { int n; VI sz(3); cin >> n; FOR(i, 0, 3) cin >> sz[i]; VI a(n); for (int& ai : a) cin >> ai; sort(ALL(a)); VI indices(3); iota(ALL(indices), 0); sort(ALL(indices), [&](int i, int j) { return sz[i] > sz[j]; }); vector ans(3); FOR(i, 0, sz[indices[0]]) ans[indices[0]].PB(a[i]); FOR(i, sz[indices[0]], sz[indices[0]] + sz[indices[1]]) ans[indices[1]].PB(a[i]); FOR(i, sz[indices[0]] + sz[indices[1]], n) ans[indices[2]].PB(a[i]); vector sum(3); FOR(i, 0, 3) sum[i] = accumulate(ALL(ans[i]), 0LL); LL tot = accumulate(ALL(a), 0LL); auto [good, idxMax] = ok(sum, tot); if (good) { print(ans); return; } int idxSmall = indices[0]; if (idxMax == idxSmall) { cout << "NO\n"; return; } assert(sz[idxMax] <= sz[idxSmall]); FOR(i, 0, sz[idxMax]) { sw(ans, sum, idxMax, i, idxSmall, i); auto [curGood, curIdxMax] = ok(sum, tot); if (curGood) { print(ans); return; } if (curIdxMax != idxMax) { assert(curIdxMax == idxSmall); sw(ans, sum, idxMax, i, idxSmall, i); FOR(j, i + 1, sz[idxSmall]) { sw(ans, sum, idxMax, i, idxSmall, j); if (ok(sum, tot).F) { print(ans); return; } sw(ans, sum, idxMax, i, idxSmall, j); } assert(i == sz[idxMax] - 1); } } cout << "NO\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) solve(); return 0; }