PRINTSPIRAL - Printing Spiral Digits


You are given two integers, the number of Rows(N) and the number of Columns(M) of a matrix. Your task is to print numbers from 1 to N*M in a spiral form. The spiral number begins from the top-left corner, continues to the top right corner, then bottom right corner, then goes to bottom left corner, and goes back up to 1 row below the top row, and then the pattern continues until the matrix is full. If the largest number is more than 9, then print 0 before the number if the number is less than 10 (see input examples for clarification).

Input

Input starts with an integer T (1 ≤ T ≤ 20), denoting the number of test cases. Each of the test cases consists of integer N and M (1 ≤ N*M ≤ 99), denoting the number of rows and columns of the matrix.

Output

For each case print "Case X:", where X (1 ≤ X ≤ T) is the case number, followed by a newline. There must be no trailing spaces at the end of printed lines, neither empty characters. After that, print the sets of number in spiral form. Print a newline after each testcase.

Example

Input:
3
4 5
3 3
2 3

Output:
Case 1:
01 02 03 04 05
14 15 16 17 06
13 20 19 18 07
12 11 10 09 08
Case 2:
1 2 3
8 9 4
7 6 5
Case 3:
1 2 3
6 5 4


hide comments
dpdocs21: 2016-12-02 10:13:28

It's just trailing spaces which were causing problem for me and not the extra line at the end. Thanks @last_phoenix

silence026: 2016-12-01 16:47:26

Don't print an extra "\n" in the end.

last_phoenix: 2016-06-14 16:39:58

Be very careful with trailing spaces at the end of printed lines....


Added by:hanstan
Date:2016-05-10
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 GOSU JS-MONKEY
Resource:Self