#include<iostream>
using namespace std;
void square3(){
	cout << "   4   9   2\n   3   5   7\n   8   1   6\n";
}
void square5(){
	cout << "  11  24   7  20   3\n";
	cout << "   4  12  25   8  16\n";
	cout << "  17   5  13  21   9\n";
	cout << "  10  18   1  14  22\n";
	cout << "  23   6  19   2  15\n";
}
void square7() {
	cout << "  22  47  16  41  10  35   4\n";
	cout << "   5  23  48  17  42  11  29\n";
	cout << "  30   6  24  49  18  36  12\n";
	cout << "  13  31   7  25  43  19  37\n";
	cout << "  38  14  32   1  26  44  20\n";
	cout << "  21  39   8  33   2  27  45\n";
	cout << "  46  15  40   9  34   3  28\n";
}
void square9() {
	cout << "  37  78  29  70  21  62  13  54   5\n";
	cout << "   6  38  79  30  71  22  63  14  46\n";
	cout << "  47   7  39  80  31  72  23  55  15\n";
	cout << "  16  48   8  40  81  32  64  24  56\n";
	cout << "  57  17  49   9  41  73  33  65  25\n";
	cout << "  26  58  18  50   1  42  74  34  66\n";
	cout << "  67  27  59  10  51   2  43  75  35\n";
	cout << "  36  68  19  60  11  52   3  44  76\n";
	cout << "  77  28  69  20  61  12  53   4  45\n";
}
void square11() {
	cout << "  56 117  46 107  36  97  26  87  16  77   6\n";
	cout << "   7  57 118  47 108  37  98  27  88  17  67\n";
	cout << "  68   8  58 119  48 109  38  99  28  78  18\n";
	cout << "  19  69   9  59 120  49 110  39  89  29  79\n";
	cout << "  80  20  70  10  60 121  50 100  40  90  30\n";
	cout << "  31  81  21  71  11  61 111  51 101  41  91\n";
	cout << "  92  32  82  22  72   1  62 112  52 102  42\n";
	cout << "  43  93  33  83  12  73   2  63 113  53 103\n";
	cout << " 104  44  94  23  84  13  74   3  64 114  54\n";
	cout << "  55 105  34  95  24  85  14  75   4  65 115\n";
	cout << " 116  45 106  35  96  25  86  15  76   5  66\n";
}
void square13() {
	cout << "  79 164  67 152  55 140  43 128  31 116  19 104   7" << endl;
	cout << "   8  80 165  68 153  56 141  44 129  32 117  20  92" << endl;
	cout << "  93   9  81 166  69 154  57 142  45 130  33 105  21" << endl;
	cout << "  22  94  10  82 167  70 155  58 143  46 118  34 106" << endl;
	cout << " 107  23  95  11  83 168  71 156  59 131  47 119  35" << endl;
	cout << "  36 108  24  96  12  84 169  72 144  60 132  48 120" << endl;
	cout << " 121  37 109  25  97  13  85 157  73 145  61 133  49" << endl;
	cout << "  50 122  38 110  26  98   1  86 158  74 146  62 134" << endl;
	cout << " 135  51 123  39 111  14  99   2  87 159  75 147  63" << endl;
	cout << "  64 136  52 124  27 112  15 100   3  88 160  76 148" << endl;
	cout << " 149  65 137  40 125  28 113  16 101   4  89 161  77" << endl;
	cout << "  78 150  53 138  41 126  29 114  17 102   5  90 162" << endl;
	cout << " 163  66 151  54 139  42 127  30 115  18 103   6  91" << endl;
}
void square15() {
	cout << " 106 219  92 205  78 191  64 177  50 163  36 149  22 135   8" << endl;
	cout << "   9 107 220  93 206  79 192  65 178  51 164  37 150  23 121" << endl;
	cout << " 122  10 108 221  94 207  80 193  66 179  52 165  38 136  24" << endl;
	cout << "  25 123  11 109 222  95 208  81 194  67 180  53 151  39 137" << endl;
	cout << " 138  26 124  12 110 223  96 209  82 195  68 166  54 152  40" << endl;
	cout << "  41 139  27 125  13 111 224  97 210  83 181  69 167  55 153" << endl;
	cout << " 154  42 140  28 126  14 112 225  98 196  84 182  70 168  56" << endl;
	cout << "  57 155  43 141  29 127  15 113 211  99 197  85 183  71 169" << endl;
	cout << " 170  58 156  44 142  30 128   1 114 212 100 198  86 184  72" << endl;
	cout << "  73 171  59 157  45 143  16 129   2 115 213 101 199  87 185" << endl;
	cout << " 186  74 172  60 158  31 144  17 130   3 116 214 102 200  88" << endl;
	cout << "  89 187  75 173  46 159  32 145  18 131   4 117 215 103 201" << endl;
	cout << " 202  90 188  61 174  47 160  33 146  19 132   5 118 216 104" << endl;
	cout << " 105 203  76 189  62 175  48 161  34 147  20 133   6 119 217" << endl;
	cout << " 218  91 204  77 190  63 176  49 162  35 148  21 134   7 120" << endl;
}
int main(){
	int l[11];
	int x;
	for (int i = 0; i < 10; i++){
		cin >> l[i];
		if (l[i] == 0){
			x = i;
			break;
		}
	}
	for (int i = 0; i < x; i++){
		if (l[i] == 3)square3();
		else if (l[i] == 5)square5();
		else if (l[i] == 7)square7();
		else if (l[i] == 9)square9();
		else if (l[i] == 11)square11();
		else if (l[i] == 13)square13();
		else if (l[i] == 15)square15();
	}
	char c;
	cin >> c;
}