//Δ_1006 #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef double DB; int n,l[11]; int solve(int x,int e){ if(e<0) return 0; if(x==0) return 1; if(x>e*2) return 0; if(x<=e) return 4*x; return 4*(e*2+1-x); } int main() { int T,i,j,x,y; LL k,s; cin>>T; while(T--){ for(i=1;i<=4;i=i+1) cin>>l[5-i]; l[5]=-1; cin>>k; s=0; for(i=0;k;i=i+1){ for(j=1;j<=4;j=j+1){ if(i%j) continue; x=solve(i/j,l[j])-solve(i/j,l[j+1]); y=min(k,(LL)x); s+=(LL)i*y; k-=y; } } cout<