//Awwawa! Dis cold yis ratten buy tEMMIE! #include #define ll long long #define maxn 100005 /*rem*/ #define mod 998244353 #define db double #define vi vector #define pb push_back #define mp make_pair #define pi pair #define fi first #define se second template bool chkmax(T &x,T y){return x bool chkmin(T &x,T y){return x>y?x=y,true:false;} using namespace std; ll ksm(ll a, ll b) { if (!b) return 1; ll ns = ksm(a, b >> 1); ns = ns * ns % mod; if (b & 1) ns = ns * a % mod; return ns; } ll sqr(ll a) { return a * a; } ll cal(ll len, ll s) { if (len >= s) { if (s == 0) return 1; return 4 * s; } else { if (2 * len < s) return 0; return 4 * (2 * len - s + 1); } } ll l[4], k; int main() { int t; cin >> t; while (t--) { cin >> l[0] >> l[1] >> l[2] >> l[3] >> k; ll res = 0; for (int i = 0; i < 1600005; i++) { ll cur = 0; for (int j = 1; j <= 4; j++) { if (i % j == 0) { int d = i / j; cur += cal(l[4 - j], d); if (j != 4) cur -= cal(l[3 - j], d); } } ll ns = min(cur, k); k -= ns; res += i * ns; if (k == 0) break; } cout << res << endl; } return 0; }