#include <iostream> using namespace std; int main() { int t; cin>>t; while(t--) { long long n,x,cost,z; cin>>n; long long c,a[27]; a[0]=0; for(int i=1;i<=26;i++) { cin>>c; a[i]=a[i-1]+c; } x=12*n; z=x/26; cost=z*(2*a[26]+(z-1)*26)/2; cost+=a[x%26]+(x%26)*z; cout<<cost<<endl; } }