![Untitled](https://camo.githubusercontent.com/ff1423554eb3cca6db3f63b389e438f4a0fd6fa7176190c050211de2d06cdc6c/68747470733a2f2f73332e75732d776573742d322e616d617a6f6e6177732e636f6d2f7365637572652e6e6f74696f6e2d7374617469632e636f6d2f34376230343766372d336531302d343639312d613032622d3064636535323761383936352f556e7469746c65642e706e673f582d416d7a2d416c676f726974686d3d415753342d484d41432d53484132353626582d416d7a2d436f6e74656e742d5368613235363d554e5349474e45442d5041594c4f414426582d416d7a2d43726564656e7469616c3d414b49415437334c324734354549505433583435253246323032333033313225324675732d776573742d322532467333253246617773345f7265717565737426582d416d7a2d446174653d3230323330333132543031303435335a26582d416d7a2d457870697265733d383634303026582d416d7a2d5369676e61747572653d3839666432643764373034336237376136383937353833386166336334643163333363633763623831343632393461396464636432663238386465343436383326582d416d7a2d5369676e6564486561646572733d686f737426726573706f6e73652d636f6e74656e742d646973706f736974696f6e3d66696c656e616d65253344253232556e7469746c65642e706e6725323226782d69643d4765744f626a656374)
import sys
sys.stdin = open("../input.txt", "r")
# 여러개의 테스트 케이스가 주어지므로, 각각을 처리합니다.
for test_case in range(1, 11):
# ///////////////////////////////////////////////////////////////////////////////////
N = int(input())
arr = [[0] + list(map(int, input().split())) + [0] for _ in range(100)]
mn = 100 * 100
for sj in range(1, 101):
si = 0
if arr[si][sj] != 1:
continue
# dj(-1, 1, 0)
# 갈 수 있는 방향성으로 좌, 우, 밑
# 좌, 우를 우선적으로 고려하여 갈 수 있으면 보낸 후
# 가지 못할 경우에 밑으로 내려가게 된다.
count, dj = 0, 0
ci, cj = si, sj
# 높이의 범위를 기준으로 while문으로 반복문을 생성한다.
while ci < 99:
count += 1
if dj == 0:
if arr[ci][cj - 1] == 1:
# 좌측으로 이동
dj = -1
cj -= 1
elif arr[ci][cj + 1] == 1:
# 우측으로 이동
dj = 1
cj += 1
else:
ci += 1
else:
if arr[ci][cj + dj] == 1:
# 진행방향에서 직진할 수 있는 경우
cj += dj
else:
# 진행방향이 끝이난 경우 밑으로 이동
dj = 0
ci += 1
# 정답을 구하기 위해 끝 경계선을 생기게 하여 1의 숫자를 제거해준다.
if mn >= count:
mn, count = count, sj - 1
print(f'#{N} {count}')