Around and Around We Go

Lay out two voices of a song as a round, aligning each voice's symbols so that simultaneous sounds share a column and gaps print as plus signs.

Medium6SimulationImplementationStringNo attempts yetTime limit2sMemory limit512 MB

Problem

A round is an arrangement in which two or more voices sing the same melodic line, each voice starting at a different time. The nursery rhyme "Row, Row, Row Your Boat" shown above is a well known round: a new voice may enter when the first voice reaches any of the '*'s.

Every syllable of the song sounds for a whole number of time units. A pause, called a rest, is written as a symbol of its own and is given a duration the same way. From the duration of every symbol and the time at which the second voice enters, you can work out which symbols of the two voices sound at the same moment.

Write a program that prints a two voice round with simultaneous symbols in the same column.

The song has LL lines. For line ii of the song, print two output lines: the first voice line, then the second voice line.

The first voice line holds the symbols of song line ii and nothing else. That line fixes one time period. The period opens when the first symbol of song line ii starts sounding and closes when the last symbol of song line ii stops sounding.

The second voice line holds, in time order, every symbol of the song that the second voice starts sounding inside that period. A symbol that starts exactly at the moment the period closes belongs to the next output pair, not this one. The last symbol of a second voice line may keep sounding after the period closes.

Columns are numbered from 0. Every position of an output line that no symbol covers holds a plus sign, '+'. A line ends with its last symbol, so no line ends with a plus sign. Each symbol starts in the leftmost column these rules allow:

  • Two symbols on the same output line are separated by at least one plus sign.
  • The first symbol of a first voice line starts in column 0.
  • Two symbols that start at the same time in their respective voices start in the same column.
  • If a symbol S2S_2 in one voice starts KK time units after a symbol S1S_1 in the other voice starts, then S2S_2 starts at least KK columns to the right of S1S_1.

The last two rules compare one voice against the other. Between two symbols of the same voice only the separation rule applies, never the difference of their start times.

A second voice line can be empty, and then an empty line is printed. Some symbols of the second voice are never printed.

Input

The first line holds two integers LL and NN. LL is the number of lines in the song, 0<L100 < L \leq 10. NN is the time at which the second voice enters, with the first voice entering at time zero, 0N1280 \leq N \leq 128.

LL pairs of lines follow.

The first line of each pair holds the symbols of that line of the song. A symbol is a string of non-whitespace characters, and a single blank separates adjacent symbols. Each of these lines is at most 80 characters long.

The second line of each pair holds one positive integer per symbol of the line above, in the same order, giving the time allocated to that symbol. Each integer is in the range 11281 \ldots 128.

Output

Print 2L2L lines, two lines for each line of the song, as described above.