Problem1272-- Text Editor

1272: Text Editor

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 2  Solved: 2
[Submit] [Status] [Web Board] [Creator:]

Description

In this problem, you are to implement a command line text editor. This text editor has n edit areas labeled from 1 to n sequentially and a clipboard with size m. The following commands are available for the text editor:

  • print c: type a single lowercase English letter c in current edit area.
  • copy: clear the clipboard and copy the last m characters in current edit area to the clipboard. If the number of characters in current edit area is less than m, just copy all the characters.
  • paste: paste all characters in the clipboard to current edit area.
  • delete: delete the last character in current edit area. If current edit area is empty, ignore this command.
  • next: move to the next edit area. If the current edit area if the n-th edit area, move to the first edit area.

Initially, all the edit areas are empty, the cursor is in the first edit area. You are given several commands and after all the commands, output all the characters in current edit area.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first line contains three integers n, q and m (1 ≤ n ≤ 10, 1 ≤ m, q ≤ 1000) − the number of edit areas, the sizeof the clipboard and the number commands.

The next q lines, each contains a command, the format is described above.

Output

For each test case, output all the characters in current edit area in a single line. If the current edit area is empty, output "Empty" (without the quotes) in a single line.

Sample Input Copy

3 
1 6 2 
print a 
print b 
copy
paste 
delete 
paste 
1 2 2 
print a 
delete 
2 10 3 
print a 
print c 
copy 
paste 
next 
paste 
paste 
delete 
copy 
paste  

Sample Output Copy

abaab 
Empty 
acaaca