// includes #include using namespace std; // macros #define pb emplace_back #define mk make_pair #define FOR(i, a, b) for(int i=(a);i<(b);++i) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--) #define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr) #define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr) #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define bit(n) (1LL<<(n)) // functions template bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;} template bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;} template istream &operator>>(istream &is, vector &vec){for(auto &v: vec)is >> v; return is;} template ostream &operator<<(ostream &os, const vector& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;} template ostream &operator<<(ostream &os, const set& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template ostream &operator<<(ostream &os, const unordered_set& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template ostream &operator<<(ostream &os, const multiset& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template ostream &operator<<(ostream &os, const unordered_multiset& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template ostream &operator<<(ostream &os, const pair &p){os << p.first << " " << p.second; return os;} template ostream &operator<<(ostream &os, const map &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;} template ostream &operator<<(ostream &os, const unordered_map &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;} // types using ll = long long int; using P = pair; // constants const int inf = 1e9; const ll linf = 1LL << 50; const double EPS = 1e-10; const int mod = 1000000007; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; // io struct fast_io{ fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);} } fast_io_; int f[16][16] = { {6,12,7,9}, {15,1,14,4}, {10,8,11,5}, {3,13,2,16} }; int e[16][16] = { {32,45,52,49,48,29,4}, {54,43,26,7,6,27,42,55}, {60,37,24,9,12,21,40,57}, {15,18,35,62,63,34,19,14}, {13,20,33,64,61,36,17,16}, {58,39,22,11,10,23,38,59}, {56,41,28,5,8,25,44,53}, {3,30,47,50,51,46,31,2}, }; int s[16][16] = { {1,240,49,224,5,236,53,220,9,232,57,216,13,228,61,212}, {255,18,207,34,251,22,203,38,247,26,199,42,243,30,195,46}, {4,237,52,221,8,233,56,217,12,229,60,213,16,225,64,209}, {254,19,206,35,250,23,202,39,246,27,198,43,242,31,194,47}, {65,176,113,160,69,172,117,156,73,168,121,152,77,164,125,148}, {191,82,143,98,187,86,139,102,183,90,135,106,179,94,131,110}, {68,173,116,157,72,169,120,153,76,165,124,149,80,161,128,145}, {190,83,142,99,186,87,138,103,182,91,134,107,178,95,130,111}, {129,112,177,96,133,108,181,92,137,104,185,88,141,100,189,84}, {127,146,79,162,123,150,75,166,119,154,71,170,115,158,67,174}, {132,109,180,93,136,105,184,89,140,101,188,85,144,97,192,81}, {126,147,78,163,122,151,74,167,118,155,70,171,114,159,66,175}, {193,48,241,32,197,44,245,28,201,40,249,24,205,36,253,20}, {63,210,15,226,59,214,11,230,55,218,7,234,51,222,3,238}, {196,45,244,29,200,41,248,25,204,37,252,21,208,33,256,17}, {62,211,14,227,58,215,10,231,54,219,6,235,50,223,2,239}, }; int ans[16][16]; int main(int argc, char const* argv[]) { int n, x, y, z; cin >> n >> y >> x >> z; x--; y--; auto g = f; if(n == 8)g = e; else if(n == 16)g = s; int X = 0, Y = 0; rep(i, n)rep(j, n){ if(g[i][j] == z){ X = i; Y = j; } } int ddx = X - x; int ddy = Y - y; rep(i, n)rep(j, n){ ans[i][j] = g[(i+ddx)%n][(j+ddy)%n]; } rep(i, n)rep(j, n){ cout << ans[i][j] << "\n "[j + 1 != n]; } return 0; }