// @adi28galaxyak
// Content: question 1
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vii;
typedef pair<int, int> pii;
#define FF first
#define SS second
#define pb(v) push_back(v)
#define mp(x,y) make_pair(x, y)
#define NITRO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define s(n) scanf("%d",&n)
#define rep(i,start,end) for(int i = start;i<end;i++)
string s = "/*+-";
ll cal(ll a, char b, ll c){
if(b=='/') return (a<0 and abs(a)%c!=0)?(a/c-1):a/c;
if(b=='*') return a*c;
if(b=='+') return a+c;
return a-c;
}
void solve(vi &a){
ll val = a[0];
int ii = 1;
int j = 0;
while (ii<a.size()){
//cout<<ii<<endl;
if (j==4) j = 0;
rep(i,j,4){
if(ii>=a.size()) break;
//cout<<val<<" "<<s[i]<<" "<<a[ii]<<endl;
val = cal(val, s[i], (ll)a[ii]);
ii++;
}
rep(i,0,j){
if(ii>=a.size()) break;
//cout<<val<<" "<<s[i]<<" "<<a[ii]<<endl;
val = cal(val, s[i], (ll)a[ii]);
ii++;
}
if(ii>=a.size()) break;
j+=1;
}
cout<<val<<"\n";
}
int main(){
if(false) {
freopen("input04.txt","r",stdin);
//freopen("out.txt","w",stdout);
}
NITRO;
int tt;cin>>tt;
while(tt--){
int n, x;
cin>>n;
vi a;
rep(i,0,n) cin>>x, a.pb(x);
solve(a);
}
}
Ly8gQGFkaTI4Z2FsYXh5YWsKLy8gQ29udGVudDogcXVlc3Rpb24gMQogCiNpbmNsdWRlICJiaXRzL3N0ZGMrKy5oIgp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCnR5cGVkZWYgbG9uZyBsb25nIGxsOwp0eXBlZGVmIHZlY3RvcjxpbnQ+IHZpOwp0eXBlZGVmIHZlY3RvcjwgdmkgPiB2aWk7CnR5cGVkZWYgcGFpcjxpbnQsIGludD4gcGlpOwojZGVmaW5lIEZGIGZpcnN0CiNkZWZpbmUgU1Mgc2Vjb25kCiNkZWZpbmUgcG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