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

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

hide comments
2024-10-15 11:56:25
Print an extra "\n" after the final testcase IMPORTANT !!!
2023-10-15 07:03:41
my brain is melting
edit : i finished it but it's still melting

Last edit: 2023-11-25 03:09:11
2020-10-16 11:57:44 Sushovan Sen
Its very annoying that this judge uses EXACT JUDGE.
Just for clarification
You should not print extra SPACE after last number at the end of each line.
You should print "\n" after last printed line of last test case.

Last edit: 2020-10-16 11:58:16
2016-12-01 16:47:26
Don't print an extra "\n" in the end.
2016-06-14 16:39:58
Be very careful with trailing spaces at the end of printed lines....
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.