Bookshelf Demo

Time Limit: 1 Second    Memory Limit: 32768 KB

The new semester starts and Polivic's girlfriend has bought a bookshelf but since she has got so many books and things are in a mess. Of course, Polivic is always willing to help.

He wants to illustrate what the bookshelf will look like. As photoshop never touches his mind, ASCII is the solution.

Input

There are multiple tests. Each case starts with two integers W and L:

W (width of the bookshelf)

L (levels of the bookshelf)

The following L lines describe each level in the form:

Hi (height of this level) Ni (number of books in this level), followed by 2Ni integers for height and width of each book.

A case with W = 0 signals the end of input and this case shall not be processed.

Output

Print each bookshelf followed with a blank line.

Notice that:

1) The top and bottom of the bookself is of one unit height, and two unit wider than the rest levels.

2) On each level the books are arranged from the left-most in the order of input.

3) The input is always legal.

Sample Input

20 2
5 2 2 1 4 2
3 1 2 2
0

Sample Output

(Refer to the image.)
Submit

Source: ZOJ Monthly, May 2003