//入力確認

#include <cstdio>
#include <cstdlib>
using namespace std;

char a[8][9];

int main(){
	int n, x, y;
	scanf("%d", &n);

	for(int i = 1; i <= n; ++i){
		for(int j = 0; j < 8; ++j){
			scanf(" %s", a[j]);
		}

		scanf("%d%d", &x, &y);
		if( a[y - 1][x - 1] != '1' ){
			*(int*)0 = 0;
		}
	}
}