Star Routes#268

Star Routes

0.1 seconds
64 megabytes
Very easy

Space travelers have found information about routes between star gates. Using the gates, it is possible to travel to another world through space hypertunnels. The routes between gates, which exist in different worlds, are represented by matrices. All gates are numbered 1 \leq i \leq 100. The route matrix has in the position if there is a direct route from gate to gate .

All other positions contain . The existence of a direct route from gate to gate does not guarantee the existence of a route from to . However, there is always in the position.

The problem is as follows. Using the given route matrix, you have to find the advanced route matrix, which shows all possible routes. This matrix provides information about whether gate is reachable from any other gate . That is, if a route from gate to gate exists and a route from gate to gate exists, then a route from to exists as well. The existence of a route is also represented by in the appropriate matrix position.

So, an advanced route can be not only direct but can also contain intermediate gates.

Input

The first line contains the matrix dimension (M \leq 100), and the next lines contain the matrix rows. The elements in each row are separated by one space. The input data are correct.

Output

The output should be the advanced route matrix, one row per line, with elements separated by one space.

Examples

Example 1

Loading
Loading