#include using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair; using tll=tuple; using ld=long double; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++) #define all(v) v.begin(),v.end() #define len(v) ((ll)v.size()) template inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template inline bool chmax(T &a,T b){ if(a(now-start).count(); return ms; } } ll n; void a(ll r,ll c,vector> &v){ v[r][c]^=1; v[r][(c-1+n)%n]^=1; v[(r-1+n)%n][c]^=1; v[(r-1+n)%n][(c-1+n)%n]^=1; } void b(ll r,ll c,vector> &v){ a(r,c,v); a(r,0,v); a(0,c,v); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; vector> v(n,vector(n,0)); rep(i,n){ rep(j,n){ char c; cin >> c; if(c=='#') v[i][j]=1; } } vector> hv=v; vector ord(n*n); rep(i,n*n) ord[i]=i; mt19937 mt; while(true){ int ms=timer::get(); if(1900<=ms) break; shuffle(all(ord),mt); vector> f(n,vector(n,0)); v=hv; while(true){ int ms2=timer::get(); if(1900<=ms2) break; bool ok=true,br=false; for(auto ij:ord){ ll i=ij/n,j=ij%n; if(v[i][j]){ if(f[i][j]){ br=true; break; } f[i][j]^=1; b(i,j,v); ok=false; } } if(br) break; if(ok){ vector ans; rep(i,n){ rep(j,n){ if(f[i][j]) ans.emplace_back(i,j); } } cout << len(ans) << '\n'; for(auto [i,j]:ans){ cout << i << ' ' << j << '\n'; } exit(0); } } } cout << "-1\n"; }