Turbo Mode

Time limit1sMemory limit128 MB

Problem

A TV can select channels directly with number keys, and it also has a turbo mode controlled by the T key on the remote.

When the user presses a number key, that channel is displayed immediately. Let the currently displayed channel be X.

If the TV is not in turbo mode and the user presses T, the TV enters turbo mode. Find the previous time before now when channel X was displayed. The turbo cycle consists of the channels displayed after that time through the current display of X, keeping only the first appearance of each channel and preserving that order. The first T press displays the first channel in this cycle, and later T presses display the next channel in the same cycle. After the end of the cycle, it starts again from the beginning.

If channel X has never been displayed before the current moment, the cycle is built from the entire display history, starting with the first selected channel and ending at the current X.

Whenever the user selects a channel with a number key, the TV leaves turbo mode.

For instance, suppose the pressed keys are 1, 2, 3, T, T, T, T, T, 2, 4, 1, T, T, T, T.

StepPressed keyExplanationDisplayed channel
11Manual selection1
22Manual selection2
33Manual selection3
4TChannel 3 has not appeared before, so the cycle starts from the first selected channel, 1.1
5TThe next channel after 1 in the cycle is 2.2
6TThe next channel after 2 in the cycle is 3.3
7TThe cycle returns to the beginning.1
8TThe next channel after 1 is 2.2
92Manual selection, leaving turbo mode.2
104Manual selection4
111Manual selection1
12TThe previous display of channel 1 was at step 7, so the cycle moves to the first new channel after it, 2.2
13TThe 2 at step 9 is skipped because 2 is already in the cycle; the next new channel is 4.4
14TThe current channel 1 is also included in the cycle.1
15TThe same cycle repeats.2

Given the sequence of key presses, determine which channel is displayed every time the T key is pressed.

The TV has 99 channels, numbered from 1 to 99, and the first pressed key is never T.

Input

The first line contains an integer N, where 1 ≤ N ≤ 10 000.

Each of the next N lines contains either a channel number or the character T. Channel numbers are between 1 and 99.

Output

For every press of the T key, output the channel displayed after that key press, one per line.