/*
ANTON GRBIN
XV. GIMNAYIJA - cod
7076
JUNIOR DIVISION
CONTEST #2
*/
#include <iostream>
using namespace std;
int po[ 9 ][ 9 ];
int main() {
int tmp, red,
com, jel, pr;
for ( int i = 0;
i < 9; i++ ) {
for ( int u =
0; u < 9; u++ ) {
cin
>> tmp;
po[ i ][
u ] = tmp;
}
}
for( int lj = 0;
lj < 5; lj++ ) {
cin >>
red >> com;
red--;
com--;
pr = 0;
for( int ts
= 1; ts < 10; ts++ ) {
jel =
0;
for(
int i = 0; i < 9; i++ ) if( po[ i ][ com ]==ts ) jel = 1;
for( int i = 0; i < 9; i++ ) if(
po[ red ][ i ]==ts ) jel = 1;
for(
int i = red-(red%3); i < red-(red%3)+3; i++ ) {
for( int u = com-(com%3); u < com-(com%3)+3; u++ ) {
if( po[ i ][ u ]==ts ) jel = 1;
}
}
if(
jel==0 ) {
if(
pr==0 ) cout << ts;
if(
ts>1 && pr == 1 ) cout << ',' << ts;
pr
= 1;
}
}
cout
<< endl;
}
return 0;
}