#include <bits/stdc++.h>
using namespace std;
#define dbg(x...) \
do { \
cout << #x << " -> "; \
err(x); \
} while (0)
void err() {
cout << endl;
}
template<class T, class... Ts>
void err(const T &arg, const Ts &... args) {
cout << arg << ' ';
err(args...);
}
#define endl "\n"
#define all(A) A.begin(), A.end()
using ll = long long;
using db = double;
using pII = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int N = 2e5 + 10;
int a[4][4], vis[10];
int sum[] = {10000, 36, 720, 360, 80, 252, 108, 72, 54, 180, 72, 180, 119, 36, 306, 1080, 144, 1800, 3600};
void RUN() {
int x = 0, y = 0;
for (int i = 1; i <= 3; ++i) {
for (int j = 1; j <= 3; ++j) {
cin >> a[i][j];
if (!a[i][j]) {
x = i, y = j;
} else {
vis[a[i][j]] = 1;
}
}
}
for (int i = 1; i <= 9; ++i) if (!vis[i]) a[x][y] = i;
for (int i = 1; i <= 3; ++i) {
cin >> x >> y;
cout << a[x][y] << endl;
}
int op;
cin >> op;
int cnt = 0;
if (op <= 3) {
for (int i = 1; i <= 3; ++i) {
cnt += a[op][i];
}
} else if (op <= 6) {
for (int i = 1; i <= 3; ++i) {
cnt += a[i][op - 3];
}
} else if (op == 7) {
for (int i = 1; i <= 3; ++i) {
cnt += a[i][i];
}
} else {
for (int i = 1, j = 3; i <= 3; ++i, --j) {
cnt += a[i][j];
}
}
cout << sum[cnt - 6] << endl;
}
int main() {
#ifdef LOCAL_JUDGE
freopen("input", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cout << fixed << setprecision(20);
RUN();
#ifdef LOCAL_JUDGE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}