In the course of Linear Algebra, the following theorem is proved:
Theorem. Let A be a square matrix of size n with entries in in . There are square matrices T and J of size n such that
The decomposition , where J is of the form described above, is called a Jordan decomposition of A. The Jordan decomposition of a matrix may fail to be unique.
Given a matrix A, we can define the matrix exp A in the following way: if is a Jordan decomposition of A, then ,
It can be proved that exp A is independent of the Jordan decomposition of A used. It can also be proved that if A is real-valued, then exp A is also real-valued. Your task is: given a matrix A, compute exp A.
For example, if
then
and
The first line of the input contains the number of the test cases, which is at most 15. The descriptions of the test cases follow. The first line of a test case description contains one integer N (1 ≤ N ≤ 8), denoting the size of the matrix A. Each of the next N lines contains N integers separated by spaces, describing the matrix A. It is guaranteed that the entries of A are between 0 and 5. The test cases are separated by blank lines.
For each test case in the input, output N lines, each containing N integers separated by spaces, describing the matrix exp A. The numbers must have at least three digits after the decimal point. Print a blank line between test cases.
Input | Output |
2 2 3 0 1 3 2 1 5 0 1 | 20.086 0.000 20.086 20.086 2.718 13.591 0.000 2.718 |