#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

namespace io {
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
    }
    
    // INPUT 
    
    // double input seems slow on CF
    void re(double& x) { string t; cin >> t; x = stod(t); } 
    void re(ld& x) { string t; cin >> t; x = stold(t); }
    template<class T> void re(T& x) { cin >> x; }
    template<class Arg, class... Args> void re(Arg& first, Args&... rest) { 
        re(first); 
        re(rest...); 
    }
    template<class T1, class T2> istream& operator>>(istream& is, pair<T1,T2>& p) {
        is >> p.f >> p.s;
        return is;
    }
    template<class T> istream& operator>>(istream& is, vector<T>& a) {
        F0R(i,sz(a)) is >> a[i];
        return is;
    }
    
    // OUTPUT 
    
    template<class T> void pr(T& x) { cout << x; }
    template<class Arg, class... Args> void pr(Arg& first, Args&... rest) { 
        pr(first); 
        cout << ' ';
        pr(rest...); 
    }
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) {
        os << '{' << a.f << ", " << a.s << '}';
        return os;
    }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
        os << '{';
        F0R(i,sz(a)) {
            if (i) os << ", ";
            os << a[i];
        }
        os << '}';
        return os;
    }
}

using namespace io;

vector<vl> cur = {{2,0},{0,4}}; 

ld comb(ld a, ll b) {
    if (a > 1e15) return a;
    ll g = __gcd((ll)a,b);
    return (ld)a/g*b;
}

ld test(int i, int j) {
    ld g = 1;
    if (i) g = comb(g,cur[i-1][j]);
    if (i+1<512) g = comb(g,cur[i+1][j]);
    if (j) g = comb(g,cur[i][j-1]);
    if (j+1<512) g = comb(g,cur[i][j+1]);
    return g;
}

set<ll> S;

void genEven() {
    vi v = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
    vi V;
    for (int i: v) {
        int cur = i;
        while (cur < 1000) {
            V.pb(cur);
            cur *= cur;
        }
    }
    sort(all(V)); reverse(all(V)); V.pop_back();
    int sz = 2;
    while (sz < 512) {
        auto a = V.back(); V.pop_back();
        auto b = V.back(); V.pop_back();
        ll c;
        if (a*b <= 70) c = a*b;
        else {
            c = V.back(); V.pop_back();
        }
        //cout << a << " " << b << " " << c << "\n";
        
        vector<vl> CUR(2*sz); F0R(i,2*sz) CUR[i].resize(2*sz);
        F0R(i,sz) F0R(j,sz) if (cur[i][j]) {
            CUR[i][j] = cur[i][j];
            CUR[2*sz-1-i][2*sz-1-j] = cur[i][j]*c;
            CUR[i+(j % 2 == 0 ? 1 : -1)][2*sz-1-j] = cur[i][j]*a;
            CUR[2*sz-1-i][j+(i % 2 == 0 ? 1 : -1)] = cur[i][j]*b;
        }
        
        cur = CUR;
        sz *= 2;
    }
    for (auto a: cur) for (auto b: a) if (b) S.insert(b);
}

void genOdd() {
    vector<pair<ll,pi>> v;
    F0R(i,512) F0R(j,512) if (cur[i][j] == 0) v.pb({test(i,j),{i,j}});
    sort(v.rbegin(),v.rend()); // cout << v.front() << "\n";
    for (auto a: v) {
        ll t = a.f+1;
        while (S.count(t)) t += a.f;
        cur[a.s.f][a.s.s] = t;
        assert (t <= (1e15));
        S.insert(t);
    }
    F0R(i,512) F0R(j,511) {
        ll x = max(cur[i][j],cur[i][j+1]), y = min(cur[i][j],cur[i][j+1]);
        assert (x % y == 1);
    }
}

int main() {
    setIO();
    genEven();
    genOdd();
    int n; re(n);
    F0R(i,n) {
        F0R(j,n) cout << cur[i][j] << " ";
        cout << "\n";
    }
}
/* 
* (Actually read this pls)
    * Rlly bad errors: int overflow, array bounds
    * Less bad errors: special cases (n=1?), set tle
    * Common sense: do smth instead of nothing
*/

Measured memory_bytes: 17140