Very Important Persons

Interview

Time limit2sMemory limit512 MB

Summary
Assign guest numbers 1 to nm to an n by m hall so seat (1,1) holds nm and numbers decrease with Manhattan distance from that seat.
Level

Medium4 of 10

Topics
Sorting, Math, Implementation, Matrix
Solved
No attempts yet

Problem

The 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; the seats in the hall are arranged in n rows, with m seats in each row. Rows are numbered from 1 to n, the seats in each row are numbered from 1 to m, and 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 number, the more important the guest. 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, and there must be no situation where a guest with a greater number sits further from the mayor than a guest with a smaller number. The distance between two seats (r1, s1) and (r2, s2) is measured as |r1 - r2| + |s1 - s2|.

Help the organizers assign guests to seats.

Input

The 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

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

Output n lines; each line must contain m integers, and the j-th integer of the i-th line must equal 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.

Examples1

  1. Example 1

    Input
    2
    2 3
    3 2
    
    Expected output
    6 4 2 
    5 3 1 
    6 4 
    5 2 
    3 1