#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
int n;
bool ok(int x, int y)
{
return 0 <= x && x < n && 0 <= y && y < n;
}
PII d1[4] = {{-1, 1}, {0, 1}, {1, -1}, {1, 0}};
PII d2[4] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
vector<string> v(n);
vector<string> ans(n, string(n, '-'));
FOR (i, 0, n) cin >> v[i];
string s = "";
int idx = 0;
int x = 0, y = 0;
while (SZ(s) < n * n)
{
idx %= 4;
s += v[x][y];
if (SZ(s) == n * n) break;
if (ok(x + d1[idx].F, y + d1[idx].S))
{
x += d1[idx].F;
y += d1[idx].S;
}
else
{
if (abs(x - y) == n - 1)
swap(d1[1], d1[3]);
idx++;
x += d1[idx].F;
y += d1[idx].S;
idx++;
}
}
idx = 0;
x = 0, y = 0;
FOR (j, 0, n * n)
{
ans[x][y] = s[j];
if (j == n * n - 1) break;
while (true)
{
int nx = x + d2[idx].F;
int ny = y + d2[idx].S;
if (ok(nx, ny) && ans[nx][ny] == '-')
{
x = nx, y = ny;
break;
}
idx++;
idx %= 4;
}
}
FOR (i, 0, n)
cout << ans[i] << '\n';
return 0;
}
fghjkqwe