#include #include #include using namespace std; using namespace atcoder; using ll = long long; //#define endl "\n"; ll Q, Y, I, W; ll A, B; void printYIW(){ for(int i = 0; i < Y; i++) cout << "y"; for(int i = 0; i < I; i++) cout << "i"; for(int i = 0; i < W; i++) cout << "w"; cout << endl; } void printIWIWI(){ ll cntiw = min(I - 1, W); ll restI = I - cntiw; ll restW = W - cntiw; for(int i = 0; i < Y; i++) cout << "y"; for(int i = 0; i < cntiw; i++) cout << "iw"; for(int i = 0; i < I; i++) cout << "i"; for(int i = 0; i < W; i++) cout << "w"; cout << endl; } void printYIWIY(){ for(int i = 0; i < Y / 2; i++) cout << "y"; for(int i = 0; i < I / 2; i++) cout << "i"; for(int i = 0; i < W; i++) cout << "w"; for(int i = 0; i < I - I / 2; i++) cout << "i"; for(int i = 0; i < Y - Y / 2; i++) cout << "y"; cout << endl; } void printX(ll cntiwiwi, ll cntlefti){ for(int i = 0; i < Y / 2; i++) cout << "y"; for(int i = 0; i < cntlefti; i++) cout << "i"; for(int i = 0; i < cntiwiwi; i++) cout << "wi"; for(int i = 0; i < W - cntiwiwi; i++) cout << "w"; for(int i = 0; i < I - cntlefti - cntiwiwi; i++) cout << "i"; for(int i = 0; i < Y - Y / 2; i++) cout << "y"; cout << endl; } int main(){ cin >> Q; for(int q = 1; q <= Q; q++){ cin >> Y >> I >> W >> A >> B; bool isOK_yiwiy = false, isOK_iwiwi = false; if(Y >= 2 && I >= 2 && W >= 1) isOK_yiwiy = true; if(I >= 3 && W >= 2) isOK_iwiwi = true; if(isOK_yiwiy){ if(isOK_iwiwi){ //両方作れる //iwiwiを含む文字列を三分探索 auto f2 = [&](ll x, ll y)->__int128{ __int128 ret = 0; __int128 left = x; for(int i = 1; i <= x; i++){ ret += left; left++; } ret += left * (W - x); ret *= (I - x - (y - 1)); return ret; }; auto f = [&](ll x)->pair<__int128, ll>{ ll l = 0, r = I - x; while(r - l > 2){ ll m1 = (l * 2 + r) / 3; ll m2 = (l + r * 2) / 3; if(f2(m1, x) < f2(m2, x)) l = m1; else r = m2; } __int128 retl = f2(l, x); __int128 retr = f2(r, x); return (retl >= retr ? make_pair(retl, l): make_pair(retr, r)); }; ll l = 2, r = min(I - 1, W); while(r - l > 2){ ll m1 = (l * 2 + r) / 3; ll m2 = (l + r * 2) / 3; if(f(m1).first < f(m2).first) l = m1; else r = m2; } auto tmpl = f(l); auto tmpr = f(r); __int128 chkl = f(l).first * (__int128)(Y / 2) * (Y - Y / 2) * A + (__int128)(l - 1) * B; __int128 chkr = f(r).first * (__int128)(Y / 2) * (Y - Y / 2) * A + (__int128)(r - 1) * B; __int128 ret1; ll cntiwiwi, cntlefti; if(chkl >= chkr){ ret1 = chkl; cntiwiwi = l; cntlefti = tmpl.second; }else{ ret1 = chkr; cntiwiwi = r; cntlefti = tmpr.second; } //(iwiwiを含む文字列の最大値)