#include<bits/stdc++.h>
using namespace std;
#define el "\n"
#define ll long long
#define ull unsigned long long
#define se second
#define fi first
#define be begin()
#define en end()
#define Faster cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
vector<pair<int,int>> vt;
bool cmp(pair<int,int> a, pair<int,int> b)
{
    if(a.fi + a.se != b.fi + b.se) return a.fi + a.se < b.fi + b.se;
    return a.fi < b.fi;
}
void findSubMatrix(int **a, int n)
{
    for(pair<int,int> x : vt) cout << "(" << x.fi << "," << x.se << ")" << el;
    cout << el;
}

void sortBySum(int **a, int n)
{
    sort(vt.begin(), vt.end(), cmp);
    for(pair<int,int> x : vt) cout << "(" << x.fi << "," << x.se << ")" << el;
    cout << el;
}

int main()
{
    Faster;
    int n; cin >> n;
    int **a = new int*[n];
    for(int i = 0; i < n; i++)
    {
        a[i] = new int[n];
    }
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++) cin >> a[i][j];
    }
    for(int i = 0; i < n - 1; i++)
    {
        for(int j = 0; j < n - 1; j++)
        {
            int ans  = 0;
            for(int x = i; x < i + 2; x++)
            {
                for(int y =j; y < j + 2; y++)
                {
                    ans += a[x][y];
                }
            }
            if(ans == 0 || ans == 4) vt.push_back({i,j});
        }
    }
    findSubMatrix(a, n);
    sortBySum(a, n);
    return 0;
}

