// In Practice, You should use the statndard input/output
// in order to receive a score properly.
// Do not use file input and output. Please be very careful.
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
int N;
int arr[15];
long long ans;
int visit[15];
int tinhdiem(int vt){
int diem1=0;
int diem2=0;
for(int i= vt+1; i<N; i++){
if(visit[i]==0){
diem1=arr[i];
break;
}
}
for(int i=vt-1; i>=0; i--){
if(visit[i]==0){
diem2=arr[i];
break;
}
}
if( diem1 !=0 && diem2 != 0 ) return diem1*diem2;
else if(diem1 !=0 && diem2==0) return diem1;
else if(diem2 !=0 && diem1==0) return diem2;
else return arr[vt];
}
void bt( int dem, long long diem){
if(dem==N){
if(ans<diem) ans=diem;
return;
}
for(int i=0; i<N; i++){
if(visit[i]==0){
visit[i]=1;
bt(dem+1, diem+ tinhdiem(i));
visit[i]=0;
}
}
}
int main(int argc, char** argv)
{
int test_case;
int T;
int Answer;
ios::sync_with_stdio(false);
freopen("text.txt", "r", stdin);
cin >> T;
/*
Read each test case from standard input.
*/
for(test_case = 1; test_case <= T; ++test_case)
{
cin>>N;
for(int i=0; i<N; i++){
cin>>arr[i];
visit[i]=0;
}
ans=0;
bt(0,0);
cout << "#" << test_case << " " << ans << endl;
}
return 0;//Your program should return 0 on normal termination.
}