cases = int(input())
max_dis = 50000
def func(ds, cell, n):
    h = []
    for _ in range(n):
        h.append([max_dis] * n)

    bfs = list()
    bfs.append((0, 0, 0))
    i = 0
    while i < len(bfs):
        ca, cb, v = bfs[i]
        h[ca][cb] = min(h[ca][cb], v)
        if ds[ca][cb] != str(1 - int(cell)):
            if ca + 1 < n and h[ca + 1][cb] > v + 1:
                bfs.append((ca + 1, cb, v + 1)) 
            if cb + 1 < n and h[ca][cb + 1] > v + 1:
                bfs.append((ca, cb + 1, v + 1))
            if ca - 1 >= 0 and h[ca - 1][cb] > v + 1:
                bfs.append((ca - 1, cb, v + 1)) 
            if cb - 1 >= 0 and h[ca][cb - 1] > v + 1:
                bfs.append((ca, cb - 1, v + 1)) 
        i += 1

    return h

for _ in range(cases):
    n = int(input())
    ds = []
    for _ in range(n):
        ds.append(list(input()))
    
    

    h0 = func(ds, '0', n)
    h1 = func(ds, '1', n)
    #print(h0)
    #print(h1)
    if h0[n - 1][n - 1] == max_dis and h1[n - 1][n - 1] == max_dis:
        print(0)
    else:
        cands = [(0, 1), (1, 0), (n - 1, n - 2), (n - 2, n - 1)]
        finished = False
        for cand in cands:
            x, y = cand
            bak = ds[x][y]
            if bak == '0':
                ds[x][y] = '1'
            else:
                ds[x][y] = '0'
            h0 = func(ds, '0', n)
            h1 = func(ds, '1', n)
            if h0[n - 1][n - 1] == max_dis and h1[n - 1][n - 1] == max_dis:
                print(1)
                print(x + 1, y + 1)
                finished = True
                break
            ds[x][y] = bak
        if finished:
            continue

        for i in range(len(cands)):
            for j in range(i + 1, len(cands)):
                x, y = cands[i]
                a, b = cands[j]
                bak = ds[x][y]
                abbak = ds[a][b]
                if bak == '0':
                    ds[x][y] = '1'
                else:
                    ds[x][y] = '0'
                if abbak == '0':
                    ds[a][b] = '1'
                else:
                    ds[a][b] = '0'
                h0 = func(ds, '0', n)
                h1 = func(ds, '1', n)
                if h0[n - 1][n - 1] == max_dis and h1[n - 1][n - 1] == max_dis:
                    print(2)
                    print(x + 1, y + 1)
                    print(a + 1, b + 1)
                    finished = True
                    break
                ds[x][y] = bak
                ds[a][b] = abbak
