// tim dau biet diem cuoi(di thang)
#include <stdio.h>
int main() {
int N, a[100][100],i,x, y, j, test_case, count, min;
int Answer;
// freopen("input.txt", "r", stdin);
for(test_case=0; test_case<10; test_case++){
Answer=0;
scanf("%d", &N);
for(i=0; i<100; i++){
for(j=0; j<100; j++)
{
scanf("%d", &a[i][j]);
}
}
min =0;
int k=2;
min=10000;
for(j=0; j<100; j++){
x=0;
count=0;
if(a[0][j]==1){
//printf("%d %d \n", a[0][j], j);
y=j;
while (x<=99){
if(y>0 && a[x][y-1]>0 && a[x][y-1]!=k){
a[x][y]=k;
y--;
count++;
}else if(y<99 && a[x][y+1]>0 && a[x][y+1]!=k ){
a[x][y]=k;
y++;
count++;
}else {
a[x][y]=k;
x++;
}
}
k++;
if(count<=min) {
min=count;
Answer = j;
}
}
}
printf("#%d ", test_case+1);
printf("%d \n", Answer);
}
return 0;
}