#include<bits/stdc++.h>
using namespace std;
int main(){
short t,n,a;
long s[21];
cin>>t;
while(t--){
cin>>n;
a=1;
while(a<=4){
cin>>s[a];
a++;
}
short b=5;
while(b<=n){
s[b]=s[b-4]+s[b-1];
b++;
}
sort(s+1, s+n+1);
cout<<s[n/2+1]<<endl;
}
return 0;
}