#pragma GCC optimize ("O3") #include "bits/stdc++.h" using namespace std; #define rep(i, b, e) for(int i = (b); i <= (e); i++) #define per(i, b, e) for(int i = (e); i >= (b); i--) #define FOR(i, b, e) rep(i, b, (e) - 1) #define SZ(x) int(x.size()) #define all(x) x.begin(), x.end() #define pb push_back #define mp make_pair #define st first #define nd second using ll = long long; using pii = pair; using vi = vector; auto &operator<<(auto &o, pair p) { return o << "(" << p.st << ", " << p.nd << ")"; } auto operator<<(auto &o, auto x)->decltype(end(x), o) { o << "{"; int i=0; for(auto e: x) o << ", " + 2*!i++ << e; return o << "}"; } #ifdef LOCAL #define deb(x...) cerr << "[" #x << "]: ", [](auto...$) { ((cerr << $ << "; "),...) << endl; }(x) #else #define deb(...) #endif const int nax = 2e5 + 5; ll a[nax]; ll prefsum[nax]; int n; int input[4]; vector s; vector kto[4]; void wypisz(){ cout << "YES" << "\n"; vector perm = {0, 1, 2}; do{ bool matches = true; rep(i, 0, 2){ if(s[perm[i]] == input[i + 1]) continue; else matches = false; } if(matches){ rep(i, 0, 2){ for(int x : kto[perm[i]]){ cout << x << " "; } cout << "\n"; } return; } }while(next_permutation(all(perm))); } void solve() { s.clear(); rep(i, 0, 3) kto[i].clear(); cin >> n >> input[1] >> input[2] >> input[3]; rep(i, 1, n) cin >> a[i]; rep(i, 1, 3) s.pb(input[i]); sort(all(s)); sort(a + 1, a + n + 1); rep(i, 1, n) prefsum[i] = prefsum[i - 1] + a[i]; int malo = s[0]; ll sum = 0; ll atMost = (prefsum[n] - 1) / 2; //rep(i, 1, n) deb(i, a[i]); if(a[n] + prefsum[s[0] - 1] > atMost){ cout << "NO" << "\n"; return; } int id = -1; rep(i, 1, malo){ sum += a[n + 1 - i]; kto[0].pb(a[n + 1 - i]); int restCnt = malo - i; if(sum + prefsum[restCnt] > atMost){ // DA SIE ! id = i; break; } } //deb("A", id); if(id == -1){ if(sum > atMost){ // NIE MA TEGO CASE! cout << "NO" << "\n"; return; } else{ // moze sie da, grupa C jest pelna !! if(prefsum[s[2]] > atMost){ cout << "NO" << "\n"; return; } per(i, 1, s[2]) kto[2].pb(a[i]); rep(i, s[2] + 1, s[2] + s[1]) kto[1].pb(a[i]); ll sum2 = prefsum[s[1] + s[2]] - prefsum[s[2]]; int akt = 1; while(sum2 > atMost){ sum2 -= kto[1][s[1] - akt]; sum2 += kto[2][s[2] - akt]; akt += 1; } akt -= 1; rep(i, 1, akt){ swap(kto[1][s[1] - akt], kto[2][s[2] - akt]); } wypisz(); return; } } else{ // da sie! int who = kto[0].back(); kto[0].pop_back(); kto[1].pb(who); int used = id; per(i, 1, n - used){ per(j, 0, 2){ if(SZ(kto[j]) < s[j]){ kto[j].pb(a[i]); break; } } } wypisz(); return; } } int main() { cin.tie(0)->sync_with_stdio(0); int tt = 1; cin >> tt; FOR(te, 0, tt) solve(); return 0; }