#C11286. Text Manipulator

    ID: 40585 Type: Default 1000ms 256MiB

Text Manipulator

Text Manipulator

You are tasked with implementing a text manipulation program. Initially, the text is empty. The program processes a sequence of commands to modify the text. The commands are provided sequentially and include:

1. add word: Append a word to the text. Each word is separated by a single space.
2. replace (old_word\ new_word): Replace all occurrences of old_word with new_word in the text.
3. remove word: Remove all occurrences of the specified word from the text.

Note that a "word" is defined as a sequence of non-space characters. Process the commands in the order they are given and output the resulting text for each test case.

inputFormat

The input begins with an integer (T) representing the number of test cases. For each test case, the first line contains an integer (N), the number of commands. The following (N) lines each contain a command which can be in one of the following forms:

- add word
- replace old_word new_word
- remove word

All commands should be processed sequentially.

outputFormat

For each test case, output the final manipulated text on a new line. Words must be separated by a single space.## sample

2
3
add hello
add world
replace world universe
4
add programming
add is
add fun
remove is
hello universe

programming fun

</p>