def solve(n, grid):
    dx = [-1, 0, 1, 0]
    dy = [0, 1, 0, -1]

    def is_valid(x, y, visited):
        if x == 1 and y == 1:
            return True
        elif x < 0 or y < 0 or x >= n or y >= n:
            return False
        for _ in range(4):
            nx, ny = x + dx[_], y + dy[_]
            if (nx, ny) in visited:
                continue
            if not (0 <= nx < n and 0 <= ny < n):
                continue
            if grid[x][y] != grid[nx][ny]:
                continue

            visited.add((nx, ny))
            if is_valid(nx, ny, visited):
                return True
            visited.discard((nx, ny))

        return False

    pos = []
    if is_valid(n - 1, n - 2, set()):
        pos.append((n, n - 1))
    if is_valid(n - 2, n - 1, set()):
        pos.append((n - 1, n))
    return pos


t = int(input())
for _ in range(t):
    n = int(input())
    g = [input() for _ in range(n)]
    pos = solve(n, g)
    if not pos:
        print(0)
    else:
        print(len(pos))
        print('\n'.join('{} {}'.format(_[0], _[1]) for _ in pos))
