text = input()
while True:
line = input()
if line == "Finish":
break
line_split = line.split()
command = line_split[0]
if command == "Replace":
old_char = line_split[1]
new_char = line_split[2]
text = text.replace(old_char, new_char)
print(text)
elif command == "Cut":
start_idx = int(line_split[1])
end_idx = int(line_split[2])
if 0 <= start_idx <= len(text) and 0 <= end_idx <= len(text):
text = text[:start_idx] + text[end_idx + 1:]
print(text)
else:
print("Invalid indices!")
elif command == "Make":
upper_lower = line_split[1]
if upper_lower == "Upper":
text = text.upper()
print(text)
else:
text = text.lower()
print(text)
elif command == "Check":
substring = line_split[1]
if substring in text:
print(f"Message contains {substring}")
else:
print(f"Message doesn't contain {substring}")
elif command == "Sum":
start_idx = int(line_split[1])
end_idx = int(line_split[2])
if 0 <= start_idx < len(text) and 0 <= end_idx < len(text):
substring = text[start_idx: end_idx + 1]
sum_char = 0
for ch in substring:
sum_char += ord(ch)
print(sum_char)
else:
print("Invalid indices!")