Students of Computer Science Department of SKIT have designed a basic Notepad for the purpose of studying the functioning and advance features in many other text editors. It is a simple text editor that supports only the following two commands:
"type c" where c is a character: Append character c to the end of the current text.
"undo t" where t is an integer: Undo all operations that were performed in the previous t seconds in reverse order.
Note :
Input :
The first line of the input contains an integer T representing the number of test cases.
Each test case starts with an integer N representing the total number of commands in the test case. Now, N lines of input follows, each line containing exactly three space separated entities
Output :
Print the resulting text after executing all the commands in a single line for each test case.
Constraints :
Case #1:
The commands are as
Second 1: type a
Second 2: type b
Second 3: type c
Second 5: undo 3
After second 2, the text is "ab". After second 3, everything is undone, and the text becomes empty. At second 4, the previous "undo" is undone, so the text becomes "ab" again. Then, the "type b" is also undone and the text becomes just "a".
Case #2:
At the end of second 3, the text is "abc". At second 5, all commands performed in the previous 3 seconds are undone in reverse order. This means 'c' is removed, and then 'b' is removed. The text becomes just "a"