In this problem we simulate a simple text editor. Given a series of keyboard input, output the final text content. Initially, the text content is empty and the cursor is at the beginning of the line. The user can:
Insert a lower-case character ('a-z') before the cursor, denoted as a lower-case character.
Erase an character before the cursor, denoted as B.
Move the cursor to the right one character at a time, denoted as R.
Move the cursor to the left one character at a time, denoted as L.
Move the cursor to the beginning of the line, denoted as H.
Move the cursor to the end of the line, denoted as E.
Move all characters before the cursor to the end without changing cursor position, denoted as M
Move all characters after the cursor to the beginning without changing cursor position, denoted as N
Hints
In this problem, you are asked to use doubly linked list to reduce the time complexity.
Remember to free memory when a linked list node is deleted. If you get Runtime Error on test case, probably there is something wrong with the pointers or there is memory leak in your program.
Make sure the time complexity is O(1) for each operation, otherwise you may get Time limit exceed
The first line is an integer T (1 <= T <= 50), meaning that there are T subtasks in the input.
In each subtask, there are two lines. The first line is an integer N(1<= N <= 10^6), being the length of the series of keyboard input. The next line is a string of length N, being the series of keyboard input.
It is guaranteed that L and B will not occur when the cursor is in the left-most position, R will not occur when the cursor is in the right-most position.
For each subtask, output the final text content in a single line.