HZNUOJ

Car Trialling

Tags:
Time Limit:  1 s      Memory Limit:   128 MB
Submission:1     AC:1     Score:99.94

Description

Car trialling requires the following of carefully worded instructions. When setting a trial, the organiser places traps in the instructions to catch out the unwary.

Write a program to determine whether an instruction obeys the following rules, which are loosely based on real car trialling instructions. BOLD-TEXT indicates text as it appears in the instruction (case sensitive), tex2html_wrap_inline61 separates options of which exactly one must be chosen, and .. expands, so A..D is equivalent to A tex2html_wrap_inline61 B tex2html_wrap_inline61 C tex2html_wrap_inline61 D .

instruction = navigational tex2html_wrap_inline61 time-keeping tex2html_wrap_inline61 navigational AND time-keeping

navigational = directional tex2html_wrap_inline61 navigational AND THEN directional

directional = how direction tex2html_wrap_inline61 how direction where

how = GO tex2html_wrap_inline61 GO when tex2html_wrap_inline61 KEEP

direction = RIGHT tex2html_wrap_inline61 LEFT

when = FIRST tex2html_wrap_inline61 SECOND tex2html_wrap_inline61 THIRD

where = AT sign

sign = "signwords"

signwords = s-word tex2html_wrap_inline61 signwords s-word

s-word = letter tex2html_wrap_inline61 s-word letter

letter = A..Z tex2html_wrap_inline61 .

time-keeping = record tex2html_wrap_inline61 change

record = RECORD TIME

change = cas TO nnn KMH

cas = CHANGE AVERAGE SPEED tex2html_wrap_inline61 CAS

nnn = digit tex2html_wrap_inline61 nnn digit

digit = 0..9 Note that s-word and nnn are sequences of letters and digits respectively, with no intervening spaces. There will be one or more spaces between items except before a period (.), after the opening speech marks or before the closing speech marks.

Input

Each input line will consist of not more than 75 characters. The input will be terminated by a line consisting of a single #.

Output

The output will consist of a series of sequentially numbered lines, either containing the valid instruction, or the text Trap! if the line did not obey the rules. The line number will be right justified in a field of 3 characters, followed by a full-stop, a single space, and the instruction, with sequences of more than one space reduced to single spaces.

Samples

input
KEEP LEFT AND THEN GO RIGHT CAS TO 20 KMH GO FIRST RIGHT AT "SMITH ST." AND CAS TO 20 KMH GO 2nd RIGHT GO LEFT AT "SMITH STREET AND RECORD TIME KEEP RIGHT AND THEN RECORD TIME #
output
1. KEEP LEFT AND THEN GO RIGHT 2. CAS TO 20 KMH 3. GO FIRST RIGHT AT "SMITH ST." AND CAS TO 20 KMH 4. Trap! 5. Trap! 6. Trap!