/* ---------------------------------------------------------------------------------- 厦门大学程序设计竞赛预选赛晋级规则 预选赛晋级规则如下: T = 20。 A = 10。 1. 预选赛晋级决赛总名额为 T 人。 2. 每次预选赛的有A个晋级名额。 3. 只有正式报名成功的选手(以下简称正式选手)才有晋级资格。 4. 每次预选赛的正式选手中的前A名有直接晋级权。 5. 在两次或者两次以上预选赛里取得晋级权的选手有权选择在哪次预选赛晋级, 并同时失去其他 预选赛的直接晋级权,失去的直接晋级权不再往下递补。在选手未做选择的情况下,默认从其第一次 获得直接晋级权的预选赛中晋级。 6. 在确定所有直接晋级选手后, 如果某个预选赛晋级人数不足A人, 则在同一次预选赛中未晋级 的正式选手中按排名往下递补选择晋级选手, 一次预选赛总共最多晋级A人。获得递补资格的选手从 其最早获得递补资格的预选赛中晋级。 ---------------------------------------------------------------------------------- */ Now, you are one of the finalists of 4th Xiamen University Programming Contest. But don't forget how you got advanced to this Final. In general, we have k preliminary contests. Given the lists of the registered contestants , the ranklists of the k preliminary contest and the decision of some contestant after the preliminary stage, you are to determine the finalists of out contest.


The input contains only one test case. The test case begin with an integer A (0 <= A <= 20) as mentioned above. The rest of the test case consists of three blocks -- Contestant List Block, Ranklist Block, Decisions Block. The Contestant List Block begins with an integer n (0 <= n <= 1000) indicating the number of the registered contestants. Then n lines follows, which represents the n distinct IDs of contestant with no more than ten characters. You can assume that there are no two lines of the same ID. The Ranklist Block begins with an integer k (0 <= k <= 1000) means there are k sub-blocks, the i-th sub-block begins with an integer ni (0 < ni <= 100) indicating the number of IDs participated in the i-th preliminary contest and is followed by ni lines presenting the ranklist from top to bottom. You can assume that there are no two lines of the same ID in a sub-block. The Decisions Block begins with an integer q (0 <= q <= 1000), which means that there will be q Emails about advancing deicision from contestant to judge team. Each the rest q lines is in the form of "ID x" (without quotation), ID is the contest ID of the sender with no more than ten characters, x (0 <= x < k) is the preliminary contest index he chooses to advance from. Some contestant may send more than one Email to judges, only the last Email sent takes effect. All IDs are case-sensitive.


You should output the finalists if any, one per line, in lexicographic order.

Sample Input

4 9 ArXoR Loneknight TheBeet aaa bbb ccc ddd eee fff 3 9 ArXoR Loneknight TheBeet aaa bbb ccc ddd eee fff 4 Loneknight ArXoR TheBeet bbb 3 TheBeet Loneknight ArXoR 2 ArXoR 0 arxor 1

Sample Output

ArXoR Loneknight TheBeet aaa bbb


厦门大学第四届程序设计竞赛 现场决赛 by ArXoR @ btALT