Jane and Tim are getting married. Both of them keep the shirts in their wardrobes arranged in the same order: first by size, then by colour. After the wedding Tim moves in, so his shirts must be merged with Jane's and arranged together, again sorted by size and then by colour.
Because several newly-wed couples share these habits, your program must be able to process more than one set of data.
The input consists of several scenarios.
Each scenario begins with a single integer $W$ ($0 < W \le 30$) on a line of its own, the number of shirts belonging to the wife. A value of $0$ in place of $W$ signals the end of the input.
The next $W$ lines each contain two uppercase letters describing one shirt: the first is its size and the second is its colour. The sizes are S, M and L. The colours are B (Blue), K (blacK), N (browN), O (Orange), P (Purple), R (Red) and W (White).
The following line contains a single integer $H$ ($0 < H \le 30$), the number of shirts belonging to the husband, followed by $H$ lines describing the husband's shirts in the same two-letter format.
For each scenario print a single line containing all of that scenario's shirts separated by single spaces. Order the shirts first by size (small before medium before large) and then, within the same size, by colour in alphabetical order of the colour letter.