There are two tables. These tables are filled with numeric data. Each column of each table has a unique name. You need to implement JOIN operation for those tables. JOIN creates a new result table by combining column values of the two tables based upon the join-predicate. The query compares each row of the first table with each row of the second to find all pairs of rows which satisfy the join-predicate. When the join-predicate is satisfied, column values for each matched pair of rows of the table are combined into a result row. The result of the join can be defined as the outcome of first taking the Cartesian product of all records in the tables (combining every record in the first table with every record in the second table) — then returning all the records which satisfy the join predicate. After that, the needed columns are picked and printed as the result. Moreover, the resulting rows should be output in lexicographic order.
The input starts with the description of the first table. The first line consists of k_1 (2 \leq k_1, k_2 \leq 10) names of the columns of the table separated with spaces. All the names contain only lowercase Latin letters. The next line contains the number n_1 (1 \leq n_1, n_2 \leq 50000) — the number of records in the table. In each of the next n_1 lines there are k_1 integers — data written in the table. The description of the second table follows in the same format. The next line contains the number (1 \leq q \leq 10) — the number of queries. The description of each query follows in the following format:
SELECT <list of the names of columns>
JOIN ON <a name of the column from the first table> <a name of the column of the second table>
All integers in the tables are positive and less than .
For each query, print the result of the JOIN operation. You should print only the columns given in the query and in the appropriate order. The rows should be ordered lexicographically. The result of each query will not contain more than records. Print a blank line between the outputs for queries. See the example for more information.
Esempio 1