Under construction

Still being built. Things may change

ASCII Art Table

Time limit2sMemory limit128 MB

Summary
The program rebuilds merged cells from row and column spans and prints the ASCII table with cell coordinates.
Level

Medium4 of 10

Topics
Simulation, Implementation, Matrix
Solved
No attempts yet

Problem

Drawing a table in HTML takes tags. Given a compact description of a table, draw the ASCII art of that table.

A table is an mm by nn grid. One cell is two characters wide and one character tall. A 2×32 \times 3 grid is drawn like this.

 -- -- --
|11|12|13|
 -- -- --
|21|22|23|
 -- -- --

The ASCII art has 2m+12m + 1 lines, and every line has 3n+13n + 1 characters. The spaces at the start and at the end of a border line count as characters.

A table can merge several rows or several columns into one cell. For example, when the cell at row 1, column 1 merges two rows and the cell at row 2, column 2 merges two columns, the ASCII art looks like this.

 -- -- --
|11|12|13|
    -- --
|  |22   |
 -- -- --

Counting from the first line, the odd lines are horizontal borders. In the slot of column jj, write -- when the cell right above and the cell right below are different, and write two spaces when the same cell continues. The first line and the last line of the table carry -- in every column.

The even lines carry the cell contents. Such a line always starts and ends with |. Between two horizontally neighboring slots, write | when they belong to different cells, and write a space when the same cell continues.

Given mm and how many rows and columns every cell merges, draw the ASCII art.

Input

The input has several test cases. The first line of each test case has the number of rows mm. The next mm lines give the cells that start in that row, ordered from the leftmost column. The merge information of a cell is given once, at its top left slot.

When a row needs NN pieces of merge information, that line is given as follows.

N RS1 CS1 ... RSN CSN

RSkRS_k and CSkCS_k are at least 1 and at most 9, and they are the number of rows and the number of columns that the cell merges. A row that already holds cells coming down from earlier rows may need fewer numbers. When earlier rows fill a whole row, that line holds a single 0.

The input satisfies the following conditions.

  • The number of rows and the number of columns are at least 1 and at most 9.
  • Every row has the same number of columns.
  • Merged areas never overlap.
  • Every slot belongs to some cell.

There are at most 100 test cases, and the input ends with a line holding m=0m = 0.

Output

For each test case, print the ASCII art of the given table. At the top left slot of every cell, print its row number and then its column number. Print one blank line between two consecutive test cases, and print no blank line after the last one.

When a line ends with spaces, delete all of those spaces before printing the line.

Examples1

  1. Example 1

    Input
    3
    2 1 1 1 1
    2 1 1 1 1
    2 1 1 1 1
    3
    2 1 1 2 1
    1 1 1
    2 1 1 1 1
    3
    1 1 2
    2 1 1 1 1
    2 1 1 1 1
    3
    2 2 1 1 2
    1 2 2
    1 1 1
    0
    
    Expected output
     -- --
    |11|12|
     -- --
    |21|22|
     -- --
    |31|32|
     -- --
    
     -- --
    |11|12|
     --
    |21|  |
     -- --
    |31|32|
     -- --
    
     -- --
    |11   |
     -- --
    |21|22|
     -- --
    |31|32|
     -- --
    
     -- -- --
    |11|12   |
        -- --
    |  |22   |
     --
    |31|     |
     -- -- --