import sys from itertools import permutations from heapq import * from collections import deque import random import bisect from math import factorial input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) def test(N): base = [] def op(r,c): res = 0 for x in ((r-1)%N,r): for y in ((c-1)%N,c): res |= 1<<(N*x+y) return res for r in range(1,N): for c in range(1,N): act = op(r,c) ^ op(r,0) ^ op(0,c) #act = op(r,c) for b in base: act = min(act,act^b) if act != 0: base.append(act) return len(base) def solve(N,S): if N == 1: if S[0][0] == "#": return ("No",[]) return ("Yes",[]) if N == 2: c = S[0][0] if c == S[0][1] and c == S[1][0] and c == S[1][1]: res = [] if c == "." else [(0,0)] return ("Yes",res) return ("No",[]) tmp = [[int(S[i][j]=="#") for j in range(N)] for i in range(N)] op = [[0]*N for i in range(N)] cnt = 0 for i in range(1,N)[::-1]: for j in range(1,N)[::-1]: if tmp[i][j] == 0: continue op[i][j] = 1 cnt += 1 for r in [i,(i-1)%N]: for c in [j,(j-1)%N]: tmp[r][c] ^= 1 if sum(sum(a) for a in tmp): return ("No",[]) if N & 1: ccc = [op[i][:] for i in range(N)] for i in range(1,N): check = (sum(ccc[i][1:]) & 1) ^ (cnt & 1) if check == 1: for j in range(N): op[i][j] ^= 1 for j in range(1,N): check = (sum(ccc[i][j] for i in range(1,N)) & 1) ^ (cnt & 1) if check == 1: for i in range(N): op[i][j] ^= 1 else: R = [sum(op[i][1:]) & 1 for i in range(1,N)] C = [sum(op[i][j] for i in range(1,N)) & 1 for j in range(1,N)] same = R[0] if any(x!=same for x in R+C): return ("No",[]) res = [] for i in range(1,N): for j in range(1,N): if op[i][j]: res.append((i,j)) return ("Yes",res) def checker(N,S,res): tmp = [[int(S[i][j]=="#") for j in range(N)] for i in range(N)] def op(r,c): for x in ((r-1)%N,r): for y in ((c-1)%N,c): tmp[x][y] ^= 1 def act(r,c): op(r,c) op(r,0) op(0,c) for x,y in res: act(x,y) for i in range(N): if sum(tmp[i]) > 0: return False return True def make_test(N): tmp = [[0]*N for i in range(N)] def op(r,c): for x in ((r-1)%N,r): for y in ((c-1)%N,c): tmp[x][y] ^= 1 def act(r,c): op(r,c) op(r,0) op(0,c) for r in range(N): for c in range(N): if random.randint(0,99) & 1: act(r,c) S = [] for i in range(N): S.append("".join([".#"[tmp[i][j]] for j in range(N)])) return S while False: N = random.randint(2,5) S = make_test(N) ans,res = solve(N,S) if ans == "No": print("WA") print(N) for s in S: print(s) exit() if not checker(N,S,res): print("WA:construction") print(N) for s in S: print(s) exit() print("AC",N) N = int(input()) S = [input() for i in range(N)] ans,res = solve(N,S) if ans == "No": print(-1) else: print(len(res)) for x,y in res: print(x,y) #print(checker(N,S,res))