Plus
Pin


Problem description Progress
ID 38849. Switching between windows
Темы: List    Simulation tasks   

When a user is on the Windows operating system, they often have multiple applications running. Each of the applications runs in a separate window. To switch between windows, use the Alt+Tab key combination. This combination makes the active window the user was working in before switching to the currently active window.

To switch to another window, you can press the "Alt" key; and then, without releasing it, press the "Tab" key several times. To understand which window will become active after that, we will use the following model. Let n applications be running. Applications in the operating system are organized as a list and ordered in descending order of last activity time. That is, the application whose window is currently active – the first in the list, the application whose window was active before this – second, etc.

If you press the "Alt" key and then, without releasing it, press the "Tab" key k times, then the application window that is at (k mod n) + 1st place in the list will become active. Here a mod b means the remainder of dividing a by b. In other words, the operating system treats the list as cyclic, moving from the last element of the list to the first.

When a new application is launched, it is added to the top of the list.

A sequence of user actions is specified, where each action – either launching an application or switching between windows. Print a  list of application names in the order the user has accessed them.

Input
The first line contains an integer n – number of user actions ( 1 ≤ n ≤ 1000). The next n lines contain a description of the user's actions.

The launch of an application is described by the string "Run . Here "<application name"> – a string of no more than 100 Latin letters, numbers and spaces. It is separated from the word "Run"; exactly one space. All application names are different. Large and small letters are considered different.

Switching between applications is described by the string "Alt+Tab+...+Tab", here the substring "+Tab" repeated exactly as many times as the number of times the user pressed the Tab key without releasing the Alt key. This number does not exceed 100.

The first command in the input – always "Run" command.

Imprint
Print  n lines – the sequence of application names that the user was working with in the order in which their windows became active.
 

Examples
# Input Output
1 6
Run Mozilla Firefox
Run Free Pascal
Alt+Tab
Run Miranda IM
Alt+Tab+Tab
Alt+Tab+Tab+Tab
Mozilla Firefox
Free Pascal
Mozilla Firefox
Miranda IM
Free Pascal
Free Pascal