In a simplified database management system called PreQueL, names are restricted to a single character of type CHAR(1), and must be uppercase English letters (from to ). Each table can have up to columns, numbered from to . Tables are named using lowercase English letters (from to ).
The only query you can perform on this database involves first joining all tables (see the explanation at the end of this statement) and then selecting rows based on specific conditions. There are two types of conditions: column value or column1 column2, such as \textbf{a2} = \textbf{A} or \textbf{b1} = \textbf{c4}. All conditions must be satisfied simultaneously, as if they are combined using the AND operator.
Your task is to write a query processor for PreQueL that, given the tables and a set of conditions, outputs the rows that meet all the conditions. The output rows should be sorted lexicographically in ascending order.
The first line contains two integers: the number of tables (1 \le t \le 26) and the number of conditions (1 \le d \le 50).
Starting from the second line, tables are described. The first line of each table description provides the table's dimensions, r_n and c_n (1 \le c_i \le 9, 1 \le r_i \le 1000). This is followed by r_n rows, each containing exactly c_n characters. After the tables, lines specify the conditions.
Output the resulting rows, each on a separate line. It is guaranteed that no query will produce more than rows.
Example 1
The output rows should be sorted in ascending lexicographical order.
When joining tables and without any conditions, the resulting number of rows will be |\textbf{A}| \cdot |\textbf{B}|.
For example, if there are three tables (each represented as a list of rows): , \{C, D\}, \{XX, YY, ZZ\}, their join will result in a table with rows: \{ACXX, ACYY, ACZZ, ADXX, ADYY, ADZZ, BCXX, BCYY, BCZZ, BDXX, BDYY, BDZZ\}.