Second qualification round completed

Tasks

Show one task per page / all tasks on one page

"A" Very Important Persons
Time limit 1 second
Memory limit 256 megabytes

Opening ceremony of the new campus of N State University will be visited by nm very important persons. The ceremony will take place in a hall that has the form of a rectangle, seats in the hall are arranged in n rows, m seats in each row. Rows are numbered from 1 to n, seats in each row are numbered from 1 to m, the j-th seat of the i-th row is denoted as (i, j).

The organizers of the ceremony have numbered the guests from 1 to nm in accordance with their importance — the greater, the more important. The most important guest, the mayor of the city, gets the number nm. The mayor is planning to take seat (1, 1). Now the other guests must be assigned seats. The guests must be arranged according to their importance, there must be no situation that a guest with greater number is seating further from the mayor than a guest with smaller number. The distance between two seats (r1, s1) and (r2, s2) is measured as |r1 - r2| + |s1 - s2|.

Help the organizers to assign guests to seats.

Input format

Input contains several test cases. The first line contains the number of test cases t (1 ≤ t ≤ 400).

Each test case is specified with a line that contains two integers: n and m (1 ≤ n, m ≤ 20).

Output format

For each test case output the hall plan after the seats are assigned to guests.

Output n lines, each line must contain m integers, the j-th integer of the i-th line must be equal to the importance of the guest that will be assigned the seat (i, j).

If there are several valid ways to assign seats to guests, output any of them.

Examples
Input data
2
2 3
3 2
Output data
6 4 2 
5 3 1 
6 4 
5 2 
3 1 
 

Send solution

Upload Maximal size is 256kb

Log in

VK Facebook

Forgot password?

Registration

The instruction for password recovery
has been sent to your email