# 50093. String Substitution

## I'm a slow walker, but I never walk backwards.

Write a program to replace a part of a string with another string.

## Task Description

We will apply a series of commands on a string S of length L. There are two commands. The first command is p (print), which will simply print the string S. The other command is s (substitute), which will replace the first occurrence of a string A in S with another string B. The s command starts with a character ‘s’, and the first character after ‘s’ is the delimiter, which will separate the two strings A and B. For example, s/cd/ef/ has / as the delimiter, A as cd and B as ef. Therefore we will replace the first occurrence of cd in S with ef. Note that the delimiter is the first character after 's' so it can be any character. For example, if S is qwerasdfqwerzxcv and the instruction is s%qwer%zxcv%, then the delimiter is %, and A and B are qwer and zxcv, respectively. Finally S will become zxcvasdfqwerzxcv. Also note that if there is no A in S then S remain unchanged.

The following example list the commands and the outcome of the commands.

string S command delimiter result output
qwerasdfqwerzxcv s%qwer%zxcv% % zxcvasdfqwerzxcv
zxcvasdfqwerzxcv sazxca%a a %vasdfqwerzxcv
%vasdfqwerzxcv p %vasdfqwerzxcv
%vasdfqwerzxcv s3123asdf3 3 %vasdfqwerzxcv

## Subtask

• 20 points: The lengths of string A and string B are always 1.
• 30 points: The lengths of string A and string B are the same.
• 50 points: The lengths of string A and string B may be different.

## Input Format

The input contains only one test case. The first line contains the string S. The rest of the input has a series of commands. Each line has one command. It is guaranteed that the length of string S will not exceed 1023 during the operations.

1 < L < 1024
1 < length of string A in each instruction < 501
1 < length of string B in each instruction < 501

## Output Format

Print the current string if the instruction is ‘p’.

## Sample Input 1

abbcccddddeeeeeffffffs%c%a%ps/d/k/psejefeps~a~0~p


## Sample Output 1

abbaccddddeeeeeffffffabbacckdddeeeeeffffffabbacckdddeeeeeffffff0bbacckdddeeeeeffffff


## Sample Input 2

Abbcccddddeeeeeffffffs%ccc%kkk%ps/dd/cc/pskqwerkasdfkp


## Sample Output 2

AbbkkkddddeeeeeffffffAbbkkkccddeeeeeffffffAbbkkkccddeeeeeffffff


## Sample Input 3

qwerasdfzxcvs%qwer%asd%psoasdasdfzxcvoasdasdfzxcveopstasdasdfzxcve3tasdasdfzxcvetp


## Sample Output 3

asdasdfzxcvasdasdfzxcveasdasdfzxcve


## Testdata Set

Download Testdata