#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int n,mat[N][N],dp[N][(1<<N) +5];
int solve(int row, int col, int mask){
if(dp[row][mask]!=-1 )return dp[row][mask];
////////////////////////////////
if(row==n){
if(n==1)return mat[row][col];
for(int i=1; i<=n ;i++) if((mask&(1<<(i-1)))==0)return mat[row][i];
}
////////////////////////////////
int best = 0,bc=0,pre=0;
for(int i=1; i<=n; i++){
if((mask & (1<<(i-1))) == 0){
pre = best;
best = max(best, solve(row+1,i,mask | (1<<(i-1))));
}
}
return dp[row][mask]=(best+mat[row][col]);
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int t;
scanf("%d",&t);
while(t--){
int i,j;
memset(dp, -1, sizeof dp);
scanf("%d",&n);
for(i=1; i<=n; i++){
for(j=1; j<=n; j++){
scanf("%d",&mat[i][j]);
}
}
int ans = 0,mask;
for(i=1; i<=n; i++){
mask = 1<<(i-1);
ans = max(ans,solve(1,i,mask));
}
cout<<ans<<"\n";
}
return 0;
}
CiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCBpbnQgTiA9IDIwOwppbnQgbixtYXRbTl1bTl0sZHBbTl1bKDE8PE4pICs1XTsKCmludCBzb2x2ZShpbnQgcm93LCBpbnQgY29sLCBpbnQgbWFzayl7CiAgICBpZihkcFtyb3ddW21hc2tdIT0tMSApcmV0dXJuIGRwW3Jvd11bbWFza107CiAgICAvLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLwogICAgaWYocm93PT1uKXsKICAgICAgICBpZihuPT0xKXJldHVybiBtYXRbcm93XVtjb2xdOwogICAgICAgIGZvcihpbnQgaT0xOyBpPD1uIDtpKyspIGlmKChtYXNrJigxPDwoaS0xKSkpPT0wKXJldHVybiBtYXRbcm93XVtpXTsKICAgIH0KICAgIC8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vCiAgICBpbnQgYmVzdCA9IDAsYmM9MCxwcmU9MDsKICAgIGZvcihpbnQgaT0xOyBpPD1uOyBpKyspewogICAgICAgIGlmKChtYXNrICYgKDE8PChpLTEpKSkgPT0gMCl7CiAgICAgICAgICAgIHByZSA9IGJlc3Q7CiAgICAgICAgICAgIGJlc3QgPSBtYXgoYmVzdCwgc29sdmUocm93KzEsaSxtYXNrIHwgKDE8PChpLTEpKSkpOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBkcFtyb3ddW21hc2tdPShiZXN0K21hdFtyb3ddW2NvbF0pOwp9CmludCBtYWluKCkgewogICAgLyogRW50ZXIgeW91ciBjb2RlIGhlcmUuIFJlYWQgaW5wdXQgZnJvbSBTVERJTi4gUHJpbnQgb3V0cHV0IHRvIFNURE9VVCAqLyAgIAogICAgaW50IHQ7CiAgICBzY2FuZigiJWQiLCZ0KTsKICAgIHdoaWxlKHQtLSl7CiAgICAgICAgaW50IGksajsKICAgICAgICBtZW1zZXQoZHAsIC0xLCBzaXplb2YgZHApOwogICAgICAgIHNjYW5mKCIlZCIsJm4pOwogICAgICAgIGZvcihpPTE7IGk8PW47IGkrKyl7CiAgICAgICAgICAgIGZvcihqPTE7IGo8PW47IGorKyl7CiAgICAgICAgICAgICAgICBzY2FuZigiJWQiLCZtYXRbaV1bal0pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGludCBhbnMgPSAwLG1hc2s7CiAgICAgICAgZm9yKGk9MTsgaTw9bjsgaSsrKXsKICAgICAgICAgICAgbWFzayA9IDE8PChpLTEpOwogICAgICAgICAgICBhbnMgPSBtYXgoYW5zLHNvbHZlKDEsaSxtYXNrKSk7CiAgICAgICAgfQogICAgICAgIGNvdXQ8PGFuczw8IlxuIjsKICAgIH0KICAgIHJldHVybiAwOwp9Cg==