Team Arrangement

No attempts yetTime limit1sMemory limit128 MB

Problem

Barry Bennett, the coach of the Bings football team, wants to arrange his side for an important match against the Bangs. He first decides on a formation to play. For example, 4-4-2 means four defenders, four midfielders, and two strikers (and, of course, one goalkeeper). Your task is to determine which eleven players will play.

For every available player we know their role (goalkeeper, defender, midfielder, or striker). For each role, players are chosen in ascending order of their numbers: the required number of lowest-numbered players of that role are selected.

Once the eleven players are chosen, you must also determine the captain. The captain is the selected player with the longest record on the team, i.e. the greatest total number of years of membership. If two players have the same record, the one with the larger number becomes captain. The captain is always chosen from among the eleven selected players.

Input

The input consists of multiple test cases. The first 22 lines of each test case describe the 22 available players, one player per line, in the format:

number name role year1-year1' year2-year2' ...
  • number is the player's number, a unique positive integer less than 100.
  • name is a string of at most 20 letters.
  • role is a single character: G (goalkeeper), D (defender), M (midfielder), or S (striker).
  • Each yeari-yeari' pair (with yeari ≤ yeari') means the player was a member of the team from yeari to yeari', inclusive. Years are written in four-digit format. Each line contains between 1 and 20 such pairs, and no single year appears more than once among one player's pairs.

The 23rd line of each test case gives the desired formation, such as 4-4-2. A formation always consists of exactly three numbers, none of them zero, and their sum is always 10.

The input ends with a line containing a single 0.

Output

For each test case, output the eleven selected players. Each line contains the player's number, name, and role, separated by single spaces. The players are listed by role in the order goalkeeper, defenders, midfielders, strikers, and players with the same role are ordered by ascending number. The only exception is the captain, who is always printed first, on his own line, before all the others.

If the team cannot be arranged according to the desired formation (there are not enough players for some role), print a single line reading IMPOSSIBLE TO ARRANGE instead.

Separate the output of two consecutive test cases with a blank line.