import sys


def main():
    stacks_str, moves_str = sys.stdin.read().split("\n\n")

    stacks = [
        [c for c in cs if c.isalpha()]
        for cs in zip(*reversed(stacks_str.splitlines()))
        if cs[0].isdigit()
    ]

    for move_str in moves_str.splitlines():
        count, source, target = map(int, move_str.split()[1::2])

        stacks[target - 1] += stacks[source - 1][-count:]
        del stacks[source - 1][-count:]

    print("".join(stack[-1] for stack in stacks))


if __name__ == "__main__":
    main()
