#include<iostream>
#include<cstdio>
#include<vector>
#define min(x,y) ((x) < (y) ? (x) : (y))
using namespace std;
long long int calc(vector<long long int> ar,char ch,int b);
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
string st;
int b;
vector<long long int> vec;
scanf("%d",&b);
//cin>>st;
int j=0;
for(long long int k=0;k<b;k++)
{
long long int g;
scanf("%lld",&g);
vec.push_back(g);
j=j+2;
}
printf("%lld",min(calc(vec,'*',vec.size()),min(calc(vec,'+',vec.size()),calc(vec,'-',vec.size()))));
}
}
long long int calc(vector<long long int> ar,char ch,int b)
{
if(b==1)
return ar[b-1];
else if(ch=='+')
return calc(ar,'*',b-1)+ar[b-1];
else if(ch=='*')
return calc(ar,'*',b-1)*ar[b-1];
else if(ch=='-')
return calc(ar,'-',b-1)-ar[b-1];
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGNzdGRpbz4KI2luY2x1ZGU8dmVjdG9yPgojZGVmaW5lIG1pbih4LHkpICgoeCkgPCAoeSkgPyAoeCkgOiAoeSkpCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmxvbmcgbG9uZyBpbnQgY2FsYyh2ZWN0b3I8bG9uZyBsb25nIGludD4gYXIsY2hhciBjaCxpbnQgYik7CmludCBtYWluKCkKewoJaW50IG47CglzY2FuZigiJWQiLCZuKTsKCWZvcihpbnQgaT0wO2k8bjtpKyspCgl7CgkJc3RyaW5nIHN0OwoJCWludCBiOwoJCXZlY3Rvcjxsb25nIGxvbmcgaW50PiB2ZWM7CgkJc2NhbmYoIiVkIiwmYik7CgkJLy9jaW4+PnN0OwoJCWludCBqPTA7CgkJZm9yKGxvbmcgbG9uZyBpbnQgaz0wO2s8YjtrKyspCgkJewoJCQlsb25nIGxvbmcgaW50IGc7CgkJCXNjYW5mKCIlbGxkIiwmZyk7CgkJCXZlYy5wdXNoX2JhY2soZyk7CgkJCWo9aisyOwoJCX0KCQlwcmludGYoIiVsbGQiLG1pbihjYWxjKHZlYyw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