#include<cstdio>
#include<iostream>
using namespace std;
char masu[50][50] = {{0}};
void saiki(int x,int y){
    masu[y][x] = '0';

    if(masu[y+1][x] == '1') saiki(x,y+1);
    if(masu[y-1][x] == '1') saiki(x,y-1);
    if(masu[y][x+1] == '1') saiki(x+1,y);
    if(masu[y][x-1] == '1') saiki(x-1,y);
}
int main(){
    while(1){
        int cnt = 0;
        for(int i = 0; i < 12; i++){
            if(scanf("%s",masu[i]) == EOF)goto a;
        }
        for(int i = 0; i < 12; i++){
            for(int j = 0; j < 12; j++){
                if(masu[i][j] == '1'){
                    saiki(j,i);
                    cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
    a:;
    return 0;
}
#include <bits/stdc++.h>
#define ctz __builtin_ctz

const int N = 648;

int n, D1, D2;
int a[N][N];

void coloring(int dist, int bit) {
	int i, j, L = ctz(dist) / 2; dist >>= 2 * L;
	switch (dist & 3) {
		case 0: throw "gg"; break;
		case 1: for (i = 0; i < n; ++i) for (j = 0; j < n; ++j) a[i][j] |= ((i ^ j) >> L & 1) << bit; break;
		case 2: for (i = 0; i < n; ++i) for (j = 0; j < n; ++j) a[i][j] |= (i >> L & 1) << bit; break;
	}
}

int main() {
	int i, j, c, d, col[4] = {0};
	scanf("%d%d%d", &n, &D1, &D2), d = n * n, n *= 2, coloring(D1, 0), coloring(D2, 1);
	for (i = 0; i < n; ++i)
		for (j = 0; j < n; ++j) ++col[ a[i][j] ];
	c = std::max_element(col, col + 4) - col;
	for (i = 0; i < n && d; ++i)
		for (j = 0; j < n && d; ++j)
			if (a[i][j] == c) --d, printf("%d %d\n", i, j);
	return 0;
}