The input contains multiple test cases. The first line of each case is an integer N, representing the size of the template is N*N (N could only be 3, 4 or 5). Next N lines describe the template. The following line contains an integer Q, which is the Scale Level of the picture. Input is ended with a case of N=0. It is guaranteed that the size of one picture will not exceed 3000*3000.