Browser History Navigation
You're implementing a simple web browser. It maintains a history of visited URLs and supports three operations:
- VISIT(url): Navigate to the given URL. This clears any "forward" history (if the user had previously used back, those URLs are no longer reachable).
- BACK(): Go to the previous URL in the history. If already at the beginning, this does nothing.
- FORWARD(): Go to the next URL in the history. If already at the end, this does nothing.
Initially, the browser is at the first visited URL. Given a sequence of operations, output the URL at each step.
Input
The first line contains n (1 ≤ n ≤ 10^5), the number of operations.
Each of the next n lines contains one operation:
VISIT urlwhereurlis a non-empty string of lowercase letters (1 ≤ |url| ≤ 20)BACKFORWARD
The first operation is always a VISIT.
Output
For each VISIT, BACK, and FORWARD operation, print the current URL after that operation.
Constraints
- 1 ≤ n ≤ 10^5
- Each URL is 1–20 lowercase letters
- At least one operation is always a
VISIT
Notes
In the first example, after visiting github and stackoverflow, when we go BACK, we're at github. From there, if we VISIT google, the forward history is cleared and we can no longer reach stackoverflow.