Problem 04A. Browser History ≡

Author:Pavel Mesenev   Time limit:2 sec
Input file:Standard input   Memory limit:256 Mb
Output file:Standard output  

Statement

You are simulating a browser's history. The browser starts on the homepage, page 0. You are given n operations, each one of:

After every BACK and FORWARD operation, output the page you land on. VISIT produces no output.

Input format

The first line contains one integer n — the number of operations. Each of the next n lines is one operation in the format above.

Output format

For every BACK or FORWARD operation, print the resulting current page on its own line, in order.

Constraints

1 ≤ n ≤ 2 ⋅ 105

1 ≤ x ≤ 109 for VISIT x

1 ≤ k ≤ 109 for BACK k / FORWARD k

Sample tests

No. Standard input Standard output
1
10
VISIT 1
VISIT 2
VISIT 3
BACK 1
BACK 1
FORWARD 1
VISIT 4
FORWARD 2
BACK 2
BACK 7
2
1
2
4
1
0
2
1
BACK 5
0
3
2
VISIT 100
FORWARD 3
100

0.038s 0.014s 18