Exponential Function

In the course of Linear Algebra, the following theorem is proved: Theorem. Let A be a square matrix of size n with entries in C. There are square matrices T and J of size n such that  J1 0 0 0  0 J2 0 0  A=T−1JT, J= ..  00 .0 where Ji are Jordan cells: 0 0 0 Jk  λi 1 0 0 ... 0  0 λi 1 0 ... 0  .. .. .. .. .. ..  J=...... i ............  . . . . . .  0 ... ... ... λi 1  0 ... ... ... ... λi Here λi is an eigenvalue of A. The decomposition A = T−1JT , 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 A = T−1JT is a Jordan decomposition of A, then expA = T−1J′T    eλi ... ... eλi ′ 0! mi! J1 0 0  0 eyi ... eλi  ′.′0! (mi−1)! J=0 .. 0, Ji=.. .. .. ..  0 0 J′  . . . .  k 0 ... 0 eλi 0! Here mi is the size of Ji. If k ≤ l, then the number in the k-th row and l-th column of Ji′ is eλi jkl = (l−k)!, otherwise it is 0. 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.

2/2 For example, if then and Input () A=30, 13 ()()() J= 3 1 ,T= 1 1 ,J′= e3 e3 0 3 1 0 0 e3 ()() exp A = e3 0 ≈ 20.086 0 e3 e3 20086 20086 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. Output For each test case in the input, output N lines, each containing N integers separated by spaces, describing the matrix expA. The numbers must have at least three digits after the decimal point. Print a blank line between test cases. Sample Input 2 2 30 13 15 01 Sample Output 20.086 0.000 20.086 20.086 2.718 13.591 0.000 2.718