Write a program to edit a word. First you will be given a word consisting of lower letters. Each line afterward is a command. The commands are as follow.
replace x y Both $x$ and $y$ are character. You need to replace all occurrence of $x$ by $y$.
remove x Remove all occurrence of $x$.
addhead x Add a character $x$ at the beginning of the word.
addtail x Add a character $x$ at the end of the word.
end Stop the computation. It is guarantee the last command is always an end.
For example, if you are given a word "pangfeng", then after "replace g d" you will have "pandfend". Then after "remove n" you will have "padfed". After "addhead a" you will have "apadfed". After "addtail s" you will have "apadfeds".
10pt. Implement replace and end. The input is always correct.
20pt. Implement the replace, remove, and end. The input is always correct.
30pt. Implement the replace, remove, addtail, and end. The input is always correct.
30pt. Implement all commands. The input is always correct.
10pt. Implement all commands. The input command maybe incorrect. If you encounter an invalid command "xyz", output "invalid command xyz" and stop the program immediately.
It has a testdata set. First line contains a string $S$, then following many commands to edit the word.