This page is still under construction.

Parts of this page are still being built. What you see may change.

Keylogger

Interview

Time limit1sMemory limit256 MB

Summary
A log of typed keys, arrow moves, and backspaces in a text field must be replayed to recover the final password.
Level

Medium5 of 10

Topics
Linked list, Simulation, Stack
Solved
No attempts yet

Problem

A keylogger was installed on the computer Gangsan uses, and it recorded, in order, every key he typed into a password field.

Because the keylogger records every key the user presses, you can recover the real password from that log even when Gangsan pressed arrow keys or backspace.

Given the keys Gangsan pressed in the password field, write a program that determines the password that was ultimately entered. The keys Gangsan can press are only uppercase letters, lowercase letters, digits, backspace, and arrow keys.

Input

The first line contains the number of test cases. Each test case is a single line containing a string of length LL, listing the keys pressed in order. (1≤L≤1,000,0001 \le L \le 1{,}000{,}000)

Each character of the string is processed as follows.

  • -: Backspace. If there is a character immediately to the left of the cursor, delete it. (If there is none, nothing happens.)
  • <: Move the cursor one position to the left. If it is already at the leftmost position, it does not move.
  • >: Move the cursor one position to the right. If it is already at the rightmost position, it does not move.
  • Any other character: part of the password, inserted at the cursor position. If the cursor is not at the end of the line, the cursor and every character to its right shift one position to the right. After the insertion, the cursor is placed to the right of the inserted character. (This character can also be deleted later with backspace.)

Output

For each test case, print the password on its own line. The length of the password is always at least 1.

Examples1

  1. Example 1

    Input
    2
    <<BP<A>>Cd-
    ThIsIsS3Cr3t
    
    Expected output
    BAPC
    ThIsIsS3Cr3t