# python3

import sys


class Rope:
    def __init__(self, s):
        self.s = s

    def result(self):
        return self.s

    def process(self, i, j, k):
        if j - i == 1:
            self.s = self.s[:i] + k + self.s[j:]
            return

        m = (i + j) // 2
        self.process(i, m, k)
        self.process(m, j, k)


rope = Rope(sys.stdin.readline().strip())
q = int(sys.stdin.readline())
for _ in range(q):
    i, j, k = map(int, sys.stdin.readline().strip().split())
    rope.process(i, j, k)
print(rope.result())
