Abandon Ship

No attempts yetTime limit1sMemory limit256 MB

Problem

A starship captain has a long list of things to do. Even on the flagship of the fleet, plenty needs attention during a battle. Power has to be diverted, matrices have to be re-inverted, and one day you might have to reach those over decorated escape pods. That is why a new program with the long, clumsy, and completely informative name CaptainsLogStardate41254.7TheseAreTheVoyagesOfTheStarship (Enterprise Edition) is under development. Its first version supports giving orders during battle. The program handles three kinds of systems.

  • Category I: these systems go out of whack once in a while. When one does, recalibrate it.
  • Category II: these systems suddenly, and for no apparent reason, become unusable in their current state. Invert them, or re-invert them, as needed. While the captain takes care of them, the engineers are grepping the source code for do_damage_to_self.
  • Category III: life critical. Divert power to them if you can, and abandon ship if you cannot. You have 20 units of extra power.

Input

The first line contains the number of test cases TT. Then TT cases follow.

The first line of each case contains four integers AA, BB, CC, DD separated by spaces. The first three are the number of systems in Category I, II and III. The fourth is the number of damage reports.

After that line come AA lines with the names of the Category I systems, BB lines with the names of the Category II systems, CC lines with the names of the Category III systems, and DD lines with the names of the damaged systems, in the order they were damaged.

  • 0T1000 \le T \le 100
  • 0A,B,C,D1000 \le A, B, C, D \le 100
  • Each system name starts and ends with a lowercase letter from a to z.
  • Each system name is between 2 and 22 characters long and contains only lowercase letters from a to z and spaces.
  • Within one case the system names are distinct, and every damaged system name is one of the systems listed in that case.

Given a system name SYSTEM, the order to give is one of the following.

  • recalibrate SYSTEM
  • invert SYSTEM
  • re-invert SYSTEM
  • divert all power to SYSTEM
  • ABANDON SHIP. REPEAT. ALL HANDS ABANDON SHIP.

Output

For each damage report, print the correct order for your crew, one order per line.

A Category I system always needs to be recalibrated when it is damaged, so print recalibrate [system name].

A Category II system needs to be inverted the first time it is damaged, re-inverted the next time, inverted again after that, and so on. Print invert [system name] or re-invert [system name] as the state requires.

A Category III system starts with 100 units of power and loses 10 units for each damage it takes. The ship has 20 units of extra power that can be diverted to damaged systems. As long as the system is still alive after the damage, print divert all power to [system name], even when the extra power has already been spent. When you order power diverted, the crew uses only as much extra power as it needs to bring that system back to 100 units. When a Category III system is at 10 units or less after the damage, print ABANDON SHIP. REPEAT. ALL HANDS ABANDON SHIP. and end that case. Give no further orders for the remaining damage reports of that case.

The cases are independent. System power, the inverted state of Category II systems, and the 20 units of extra power all return to their starting values in every case.

Print every order in lower case except the abandon ship order, which keeps the capitalization and the punctuation exactly as written above.