// Why I am so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

vector<int> adj[2][360005];

vector<int> comp[2][2];

int id[605][605];

int u[360005];

int n, d1, d2;

void addEdge(int x1, int y1, int x2, int y2, int p) {
    if (x2 < 0 || x2 >= n * 2) {
        return;
    }

    if (y2 < 0 || y2 >= n * 2) {
        return;
    }

    adj[p][id[x1][y1]].pb(id[x2][y2]);        
}

void dfs(int v, int col, int p) {
    comp[p][col].pb(v);
    u[v] = 1;

    for (int to : adj[p][v]) {
        if (u[to]) {
            continue;
        }

        dfs(to, col ^ 1, p);
    }
}

vector<pair<int, int>> calc(vector<int> a, vector<int> b) {
    static vector<pair<int, int>> ret;
    ret.clear();

    for (int x = 0; x < n * 2; ++x) {
        for (int y = 0; y < n * 2; ++y) {
            u[id[x][y]] = 0;
        }
    }

    for (int x : a) {
        ++u[x];
    }

    for (int x : b) {
        ++u[x];
    }

    for (int x = 0; x < n * 2; ++x) {
        for (int y = 0; y < n * 2; ++y) {
            if (u[id[x][y]] == 2) {
                ret.pb(mp(x, y));
            }
        }
    }

    return ret;
}
   
void solve() {                   
    scanf("%d %d %d", &n, &d1, &d2);     

    for (int i = 0, c = 0; i < n * 2; ++i) {
        for (int j = 0; j < n * 2; ++j) {
            id[i][j] = ++c;
        }
    }

    vector<pair<int, int>> vv1, vv2;

    for (int a = 0; a <= 500; ++a) {
        for (int b = 0; b <= 500; ++b) {
            int cur = a * a + b * b;
            
            if (cur == d1) {
                vv1.pb(mp(a, b));
            }
            
            if (cur == d2) { 
                vv2.pb(mp(a, b));            
            }
        }
    }

    for (int x = 0; x < n * 2; ++x) {
        for (int y = 0; y < n * 2; ++y) {
            for (auto it : vv1) {
                addEdge(x, y, x + it.fi, y + it.se, 0);
                addEdge(x, y, x + it.fi, y - it.se, 0);
                addEdge(x, y, x - it.fi, y + it.se, 0);
                addEdge(x, y, x - it.fi, y - it.se, 0);
            }

            for (auto it : vv2) {
                addEdge(x, y, x + it.fi, y + it.se, 1);
                addEdge(x, y, x + it.fi, y - it.se, 1);
                addEdge(x, y, x - it.fi, y + it.se, 1);
                addEdge(x, y, x - it.fi, y - it.se, 1);
            }
        }    
    }

    for (int p = 0; p < 2; ++p) {
        for (int x = 0; x < n * 2; ++x) {
            for (int y = 0; y < n * 2; ++y) {
                u[id[x][y]] = 0;                
            }
        }

        for (int x = 0; x < n * 2; ++x) {
            for (int y = 0; y < n * 2; ++y) {
                if (!u[id[x][y]]) {
                    dfs(id[x][y], 0, p);
                }                  
            }
        }
    }

    for (int a = 0; a < 2; ++a) {
        for (int b = 0; b < 2; ++b) {
            vector<pair<int, int>> cur = calc(comp[0][a], comp[1][b]);

            if (cur.size() >= n * n) {
                for (int i = 0; i < n * n; ++i) {
                    printf("%d %d\n", cur[i].fi, cur[i].se);
                }

                return;
            }
        }
    }                         
}

int main() { 
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 125244