James has a problem. He assembled a rectangular plaque from a lot of square tiles, each with a lower-case letter or blank.
The plaque fell down and broke into jagged pieces.
While James was reaching for the glue gun his faithful dog Buster pushed the pieces around.
Fortunately, Buster has not flipped a piece over - after all he was using his nose - but he did manage to rotate a few of the pieces and he has nudged all letters to be upright again. James fears that Buster even buried a piece or two, in which case the plaque would be lost forever.
James needs all the help he can get �� write a program to try and reassemble the plaque.
Input
The first line contains two positive integers w and n, the number of words on the plaque and the number of pieces. The next w lines contain one word each, not necessarily in the right order.
Words consist of lower-case letters. On the plaque, words are separated by single blanks and wrap around. There may be trailing blanks at the bottom right of the plaque.
Finally, for each of the n pieces there is one line with two positive integers r and c, the number of rows and columns for a rectangle which can just contain the piece; this line is followed by r lines with c non-blank characters each, where an underscore represents a blank tile and # represents a tile position which is not part of the piece; all other characters are lower-case.
Output
Your program must print the assembled plaque (with underscores for blanks) or the words "No solution". Print a blank line between two consecutive test cases.
Sample Input
9 8
brown
dog
fox
jumped
lazy
over
quick
the
the
3 4
##p#
##o#
eht
3 4
e###
xo##
ciuq
4 3
#k#
##
#r#
do
4 2
_b
ju
_t
#g
3 3
r##
m##
he
3 3
_##
ndl
we#
3 3
#v#
foz
#_a
1 1
y
Sample Output
the_quick_b
rown_fox_ju
mped_over_t
he_lazy_dog