import java.io.*;
import java.util.*;

public class matrix_as implements Runnable {

    public void solve() throws IOException {
        Scanner in = new Scanner(new File("matrix.in"));
        PrintWriter out = new PrintWriter(new File("matrix.out"));

        ArrayList<String> matrix = new ArrayList<String>();
        while (in.hasNext()) {
            matrix.add(in.next());
        }
        int n = matrix.size();
        int[][] c = new int[n][n];
        char[][] a = new char[n][n];
        for (int i = 0; i < n; i++) {
            String s = matrix.get(i);
            for (int j = 0; j < n; j++) {
                a[i][j] = s.charAt(j);
                c[i][j] = s.charAt(j) - 'a';
            }
        }

        int[] x = new int[n * n];
        int[] y = new int[n * n];
        int[] h = new int[n * n];
        int[] cnt = new int['z' - 'a' + 1];
        int[] map = new int['z' - 'a' + 1];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cnt[c[i][j]]++;
            }
        }
        int cn = 0;
        for (int i = 0; i < cnt.length; i++) {
            if (cnt[i] > 0) {
                map[i] = cn;
                cn++;
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                c[i][j] = map[c[i][j]];
            }
        }
        Arrays.fill(cnt, 0);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cnt[c[i][j]]++;
            }
        }
        for (int i = 0; i < cn; i++) {
            for (int j = 0; j < i; j++) {
                h[i] += cnt[j];
            }
        }


        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                x[h[c[i][j]]] = i;
                y[h[c[i][j]]] = j;
                h[c[i][j]]++;
            }
        }
        for (int i = cn - 1; i > 0; i--) {
            h[i] = h[i - 1];
        }
        h[0] = 0;
        int l = 1;
        int mask = n - 1;

        int[] nx = new int[n * n];
        int[] ny = new int[n * n];
        int[][] nc = new int[n][n];
        while (l < n) {
            for (int k = 0; k < n * n; k++) {
                int i = x[k];
                int j = (y[k] - l) & mask;
                int cc = c[i][j];
                nx[h[cc]] = i;
                ny[h[cc]] = j;
                h[cc]++;
            }
            int col = -1;
            int pc1 = -1;
            int pc2 = -1;
            for (int k = 0; k < n * n; k++) {
                int i = nx[k];
                int j = ny[k];
                int c1 = c[i][j];
                int c2 = c[i][(j + l) & mask];
                if (c1 != pc1 || c2 != pc2) {
                    col++;
                    h[col] = k;
                }
                nc[i][j] = col;
                pc1 = c1;
                pc2 = c2;
            }

            int[] tmp = nx; nx = x; x = tmp;
            tmp = ny; ny = y; y = tmp;
            int[][] tmp2 = nc; nc = c; c = tmp2;
            l *= 2;
        }

        l = 1;
        while (l < n) {
            for (int k = 0; k < n * n; k++) {
                int i = (x[k] - l) & mask;
                int j = y[k];
                int cc = c[i][j];
                nx[h[cc]] = i;
                ny[h[cc]] = j;
                h[cc]++;
            }
            int col = -1;
            int pc1 = -1;
            int pc2 = -1;
            for (int k = 0; k < n * n; k++) {
                int i = nx[k];
                int j = ny[k];
                int c1 = c[i][j];
                int c2 = c[(i + l) & mask][j];
                if (c1 != pc1 || c2 != pc2) {
                    col++;
                    h[col] = k;
                }
                nc[i][j] = col;
                pc1 = c1;
                pc2 = c2;
            }

            int[] tmp = nx; nx = x; x = tmp;
            tmp = ny; ny = y; y = tmp;
            int[][] tmp2 = nc; nc = c; c = tmp2;
            l *= 2;
        }

        int ax = x[0];
        int ay = y[0];

        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                sb.append(a[(ax + i) & mask][(ay + j) & mask]);
            }
            sb.append('\n');
        }

        out.print(sb.toString());

        in.close();
        out.close();
    }

    public void run() {
        try {
            solve();
        } catch (IOException e) {
            System.exit(64);
        }
    }

    public static void main(String[] arg) throws IOException {
        new Thread(new matrix_as()).start();
    }
}
