import java.io.FileInputStream;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.InputStream;
import java.util.List;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.IOException;
import java.io.FileOutputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author ilyakor
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream;
		try {
			inputStream = new FileInputStream("higher.in");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		OutputStream outputStream;
		try {
			outputStream = new FileOutputStream("higher.out");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskH solver = new TaskH();
		try {
			int testNumber = 1;
			while (true)
				solver.solve(testNumber++, in, out);
		} catch (UnknownError e) {
			out.close();
		}
	}
}

class TaskH {
    OutputWriter out;

    BigInteger[][] a;
    BigInteger[][] l, lRev, r, rRev;

    public void solve(int testNumber, InputReader in, OutputWriter out) {
        this.out = out;
        int n = in.nextInt();
        if (n == 0) throw new UnknownError();

        a = new BigInteger[n][n];
        BigInteger[][] aOld = new BigInteger[n][n];
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j) {
                a[i][j] = BigInteger.valueOf(in.nextInt());
                aOld[i][j] = a[i][j];
            }
        l = diag(n);
        lRev = diag(n);
        r = diag(n);
        rRev = diag(n);

        for (int i = 0; i < n; ++i) {
            subMatrixGcd(i);
            if (a[i][i].equals(BigInteger.ZERO)) continue;
            for (int j = i + 1; j < n; ++j) {
                //Assert.assertTrue(a[j][i].mod(a[i][i]).equals(BigInteger.ZERO));
                BigInteger div = div(a[j][i], a[i][i]);
                subtractRow(j, i, div);
            }
            for (int j = i + 1; j < n; ++j) {
                //Assert.assertTrue(a[i][j].mod(a[i][i]).equals(BigInteger.ZERO));
                BigInteger div = div(a[i][j], a[i][i]);
                subtractCol(j, i, div);
            }
        }

        printMatr(l);
        lRev = inverse(l);
        printMatr(lRev);
        printMatr(r);
        rRev = inverse(r);
        printMatr(rRev);


        BigInteger[][] diag = multiply(l, lRev);
        assertUni(diag);
        diag = multiply(r, rRev);
        assertUni(diag);

        diag = multiply(multiply(l, aOld), r);
        assertDiag(diag);
    }

    private void assertUni(BigInteger[][] a) {
        for (int i = 0; i < a.length; ++i)
            for (int j = 0; j < a[i].length; ++j) {
                if (i == j) Assert.assertTrue(a[i][j].equals(BigInteger.ONE));
                else  Assert.assertTrue(a[i][j].equals(BigInteger.ZERO));
            }
    }

    private void assertDiag(BigInteger[][] a) {
        for (int i = 0; i < a.length; ++i)
            for (int j = 0; j < a[i].length; ++j) {
                if (i == j) {
                    if (i > 0 && a[i][i].compareTo(BigInteger.ZERO) != 0)
                        Assert.assertTrue(a[i][i].abs().mod(a[i - 1][i - 1].abs()).equals(BigInteger.ZERO));
                }  else  Assert.assertTrue(a[i][j].equals(BigInteger.ZERO));
            }
    }

    private void subtractRow(int target, int source, BigInteger coef) {
        for (int i = 0; i < a[target].length; ++i) {
            a[target][i] = a[target][i].subtract(a[source][i].multiply(coef));
            l[target][i] = l[target][i].subtract(l[source][i].multiply(coef));
        }
    }

    private void multRow(int target, int coef) {
        for (int i = 0; i < a[target].length; ++i) {
            a[target][i] = a[target][i].multiply(BigInteger.valueOf(coef));
            l[target][i] = l[target][i].multiply(BigInteger.valueOf(coef));
        }
    }

    private void subtractCol(int target, int source, BigInteger coef) {
        for (int i = 0; i < a.length; ++i) {
            a[i][target] = a[i][target].subtract(a[i][source].multiply(coef));
            r[i][target] = r[i][target].subtract(r[i][source].multiply(coef));
        }
    }

    private void multCol(int target, int coef) {
        for (int i = 0; i < a.length; ++i) {
            a[i][target] = a[i][target].multiply(BigInteger.valueOf(coef));
            r[i][target] = r[i][target].multiply(BigInteger.valueOf(coef));
        }
    }


    void swapRows(int x, int y) {
        BigInteger[] tmp = a[x];
        a[x] = a[y];
        a[y] = tmp;

        tmp = l[x];
        l[x] = l[y];
        l[y] = tmp;
    }

    void swapCols(int x, int y) {
        for (int i = 0; i < a.length; ++i) {
            BigInteger tmp = a[i][x];
            a[i][x] = a[i][y];
            a[i][y] = tmp;

            tmp = r[i][x];
            r[i][x] = r[i][y];
            r[i][y] = tmp;
        }
    }

    private void subMatrixGcd(int from) {
        int n = a.length;
        for (int col = n - 1; col >= from; --col) {
            if (col + 1 < n) {
                GcdRow(from, col, col + 1);
            }
            for (int row = from + 1; row < n; ++row) {
                GcdCol(col, from, row);
            }
        }
    }

    void GcdCol(int col, int row1, int row2) {
        if (a[row1][col].compareTo(BigInteger.ZERO) < 0) {
            multRow(row1, -1);
        }
        if (a[row2][col].compareTo(BigInteger.ZERO) < 0) {
            multRow(row2, -1);
        }
        while (a[row2][col].compareTo(BigInteger.ZERO) != 0) {
            BigInteger div = div(a[row1][col], a[row2][col]);
            subtractRow(row1, row2, div);
            swapRows(row1, row2);
        }
    }

    void GcdRow(int row, int col1, int col2) {
        if (a[row][col1].compareTo(BigInteger.ZERO) < 0) {
            multCol(col1, -1);
        }
        if (a[row][col2].compareTo(BigInteger.ZERO) < 0) {
            multCol(col2, -1);
        }
        while (a[row][col2].compareTo(BigInteger.ZERO) != 0) {
            BigInteger div = div(a[row][col1], a[row][col2]);
            subtractCol(col1, col2, div);
            swapCols(col1, col2);
        }
    }


    private void printMatr(BigInteger[][] a) {
        for (int i = 0; i < a.length; ++i) {
            for (BigInteger x : a[i])
                out.print(x + " ");
            out.printLine();
        }
        out.printLine();
    }

    private BigInteger[][] diag(int n) {
        BigInteger[][] res = new BigInteger[n][n];
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                res[i][j] = i == j ? BigInteger.ONE: BigInteger.ZERO;
        return res;
    }

    private BigInteger[][] inverse(BigInteger[][] a) {
        int n = a.length;
        BigInteger[][] res = new BigInteger[n][n];
        BigInteger det = calcDet(a);
        for (int x = 0; x < n; ++x) {
            for (int y = 0; y < n; ++y) {
                BigInteger[][] minor = new BigInteger[n - 1][n - 1];
                for (int i = 0, row = 0; i < n; ++i) {
                    if (i == y) continue;
                    for (int j = 0, col = 0; j < n; ++j) {
                        if (j == x) continue;
                        minor[row][col] = a[i][j];
                        ++col;
                    }
                    ++row;
                }
                BigInteger val = calcDet(minor);
                res[x][y] = div(val, det);
                if ((x + y) % 2 == 1)
                    res[x][y] = res[x][y].negate();
            }
        }
        return res;
    }

    private BigInteger calcDet(BigInteger[][] a) {
        int n = a.length;
        int[] p = new int[n];
        for (int i = 0; i < n; ++i) {
            p[i] = i;
        }
        BigInteger res = BigInteger.ZERO;
        do {
            int s = 1;
            for (int i = 0; i < n; ++i)
                for (int j = i + 1; j < n; ++j)
                    if (p[i] > p[j]) s = -s;
            BigInteger val = BigInteger.valueOf(s);
            for (int i = 0; i < n; ++i)
                val = val.multiply(a[i][p[i]]);
            res = res.add(val);
        } while (Permutations.nextPermutation(p));
        return res;
    }

    BigInteger[][] multiply(BigInteger[][] a, BigInteger[][] b) {
        int n = a.length;
        BigInteger[][] res = new BigInteger[n][n];
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                res[i][j] = BigInteger.ZERO;
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                for (int k = 0; k < n; ++k)
                    res[i][j] = res[i][j].add(a[i][k].multiply(b[k][j]));
        return res;
    }

    BigInteger div(BigInteger a, BigInteger b) {
        BigInteger res = a.abs().divide(b.abs());
        if (b.compareTo(BigInteger.ZERO) < 0)
            res = res.negate();
        if (a.compareTo(BigInteger.ZERO) < 0)
            res = res.negate();
        return res;
    }
}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0) {
                writer.print(' ');
            }
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

}

class InputReader {
    private InputStream stream;
    private byte[] buffer = new byte[10000];
    private int cur;
    private int count;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public static boolean isSpace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public int read() {
        if (count == -1) {
            throw new InputMismatchException();
        }
        try {
            if (cur >= count) {
                cur = 0;
                count = stream.read(buffer);
                if (count <= 0)
                    return -1;
            }
        } catch (IOException e) {
            throw new InputMismatchException();
        }
        return buffer[cur++];
    }

    public int readSkipSpace() {
        int c;
        do {
            c = read();
        } while (isSpace(c));
        return c;
    }

    public int nextInt() {
        int sgn = 1;
        int c = readSkipSpace();
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9') {
                throw new InputMismatchException();
            }
            res = res * 10 + c - '0';
            c = read();
        } while (!isSpace(c));
        res *= sgn;
        return res;
    }

}

class Assert {

    public static void assertTrue(boolean flag) {
        if (!flag)
        while (true);
//        if (!flag)
//            throw new AssertionError();
    }

}

class Permutations {

    public static boolean nextPermutation(int[] p) {
		for (int a = p.length - 2; a >= 0; --a)
			if (p[a] < p[a + 1])
				for (int b = p.length - 1;; --b)
					if (p[b] > p[a]) {
						int t = p[a];
						p[a] = p[b];
						p[b] = t;
						for (++a, b = p.length - 1; a < b; ++a, --b) {
							t = p[a];
							p[a] = p[b];
							p[b] = t;
						}
						return true;
					}
		return false;
	}

}
