#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 16 + 10;
int a[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    for (int i = 1; i <= 16; ++i) {
        for (int j = 1; ; ++j) {
            int x = i * j;
            int y = 720720 - x;
            int z = pow(y, .25);
            if (z * z * z * z == y && z >= 1) {
//                cout << i << '\t' << x << '\t' << y << '\t' << z << endl;
                a[i] = x;
                break;
            }
        }
    }
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            int x;
            cin >> x;
            cout << ((i + j) % 2 ? 720720 : a[x]) << ' ';
        }
        cout << endl;
    }
}
