The Love Trip

0

0 votes
Easy
Problem

Rahul bought a new bike to visit different places with his friends. Monika once got Rahul ready to visit places with her, as she likes travelling a lot. For that day, Monika can command Rahul to go anywhere and Rahul will have to follow the order.

Here are the list of commands that can be issued by Monika:

  1. BACK: If there is no previous places to visit then this command will be ignored by Rahul. Else, Rahul will have to take Monika back to the previous place they visited just before coming here.

  2. FORWARD: If there is no next place to visit then Rahul will ignore this command. Else, Rahul will take Monika to the place they just came back from.

  3. VISIT : Rahul will take Monika to the specified place.

  4. QUIT: Monika got fed up from Rahul and will leave his bike. She will go back to college from NIT bus. This marks the end of Monika's trip.

Rahul always starts his bike from 'NIT'

Input :-
Input starts with an integer T (≤ 20), denoting the number of test cases.

Each case contains some commands. The keywords BACK, FORWARD, VISIT, and QUIT are all in uppercase. The name of places have no whitespace and have at most 50 characters. The end of case is indicated by the QUIT command and it shouldn't be processed. Each case contains at most 10^5 lines.

Output :-
For each case, print the case number first. For each command, print the current place Rahul and Monika are in (in a line) after the command is executed and not ignored. Otherwise, print 'Ignored'.

Constraints :-

1 <= T <= 20
1 <= |name of places| <= 50, where |x| denotes length of string x
1 <= number of operations <= 100000

Problem Setter :-
Abhishek Keshri

Time Limit: 2
Memory Limit: 256
Source Limit:
Editor Image

?