import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Main {
static int n;
static int matrix[][];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
matrix = new int[n + 1][n + 1];
for (int i = 1; i <= n; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
for (int j = 1; j <= n; j++) {
int tmp = Integer.parseInt(st.nextToken());
matrix[i][j] = tmp;
}
}
for (int k = 1; k <= n; k++) {
for (int s = 1; s <= n; s++) {
for (int e = 1; e <= n; e++) {
if (matrix[s][k] == 1 && matrix[k][e] == 1)
matrix[s][e] = 1;
}
}
}
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
for (int r = 1; r <= n; r++) {
for (int c = 1; c <= n; c++) {
bw.write(matrix[r][c] + " ");
}
bw.write("\n");
}
bw.close();
}
}