#include <bits/stdc++.h>
using namespace std;

int board[8][8];
vector<int> ds[64];
int dx[] = {-2, -2, -1, -1, 1, 1, 2, 2};
int dy[] = {1, -1, 2, -2, 2, -2, -1, 1};
const int N = 64;
int path[N];
bool vis[N];
int x, y, s;
vector<pair<int, int>> qu(64);
int res[8][8];

void xay() {
    int cnt = 0;
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
            qu[cnt] = {i, j};
            cnt++;
        }
    }
}

bool check(int x, int y) {
    return (x >= 0 && x < 8 && y >= 0 && y < 8);
}

void convert() {
    int cnt = 0;
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
            board[i][j] = cnt++;
        }
    }
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
            for (int k = 0; k < 8; k++) {
                int nx = i + dx[k], ny = j + dy[k];
                if (check(nx, ny)) {
                    ds[board[i][j]].push_back(board[nx][ny]);
                }
            }
        }
    }
}

bool issafe(int v, int pos) {
    if (find(ds[path[pos - 1]].begin(), ds[path[pos - 1]].end(), v) == ds[path[pos - 1]].end()) {
        return false;
    }
    return !vis[v];
}

bool hal(int pos) {
    if (pos == 64) return true;
    sort(ds[path[pos - 1]].begin(), ds[path[pos - 1]].end(), [](int a, int b) {
        return ds[a].size() < ds[b].size();
    });

    for (int v : ds[path[pos - 1]]) {
        if (issafe(v, pos)) {
            path[pos] = v;
            vis[v] = true;
            if (hal(pos + 1)) return true;
            path[pos] = -1;
            vis[v] = false;
        }
    }
    return false;
}

void doi() {
    int cnt = 1;
    for (int i = 0; i < 64; i++) {
        int temp = path[i];
        int z = qu[temp].first, t = qu[temp].second;
        res[z][t] = cnt++;
    }
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
            cout << res[i][j] << ' ';
        }
        cout << endl;
    }
}

void tim() {
    memset(path, -1, sizeof(path));
    memset(vis, false, sizeof(vis));
    path[0] = s;
    vis[s] = true;
    if (hal(1)) {
        doi();
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("output.txt", "w", stdout);
    convert();
    xay();  
    cin >> x >> y;
    s = board[y - 1][x - 1];  
    tim();
    return 0;
}
