字符串题
"""
AcrosstheGreatWall,wecanreacheverycornerintheworld
5
10 18 ery cor
32 40 , we
1 6 tW all
14 18 rnerr eache
1 1 e r
"""
s = input()
n = int(input())
for _ in range(n):
words = input().split()
start = int(words[0]) - 1
end = int(words[1])
str1, str2 = words[2:]
tmp = s[start:end]
s = s[:start] + s[end:]
idx = s.find(str1 + str2)
if idx == -1:
s += tmp
else:
idx += len(str1)
s = s[:idx] + tmp + s[idx:]
print(s)