Join
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 return all the records which satisfy the join predicate. After that needed column are picked and printed as the result. Moreover the resulting rows should be output in the lexicographic order.
Input
The input starts with the description of the first table. The first line consists of k_1 (2 ≤k_1, k_2 ≤ 10) names of the columns of the table separated with spaces. All the names contain only small latin letters and digits. Next line contain number n_1 (1 ≤ n_1, n_2 ≤ 50000) — the amount 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 in the same format follows. Next line is number q (1 ≤ q ≤ 10) — the amount 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 the integers in the tables are positive and less than 100000.
Output For each query print the result of 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 won't contain more than 50000 records. Prints a blank line between the responses to queries. See the example for more information.