#include <stdio.h>#include <string.h>#define MAXN 8inta[MAXN][MAXN], vis[3][2*MAXN];
intnum, ans;
voiddfs(intcur);
intmain()
{
intk, i, j, l;
#ifndef ONLINE_JUDGEfreopen("d:\\uva_in.txt", "r", stdin);
#endifscanf("%d", &k);
for (i=0; i<k; i++) {
for (j=0; j<MAXN; j++)
for (l=0; l<MAXN; l++)
scanf("%d", &a[j][l]);
memset(vis, 0, sizeof(vis));
ans=0;
num=0;
dfs(0);
printf("%5d\n", ans);
}
return0;
}
voiddfs(intcur)
{
inti;
if (cur==MAXN) {
if (num>ans)
ans=num;
} else {
for (i=0; i<MAXN; i++) {
if (!vis[0][i] &&!vis[1][cur+i] &&!vis[2][i-cur+MAXN]) {
vis[0][i] =vis[1][cur+i] =vis[2][i-cur+MAXN] =1;
num+=a[cur][i];
dfs(cur+1);
num-=a[cur][i];
vis[0][i] =vis[1][cur+i] =vis[2][i-cur+MAXN] =0;
}
}
}
}