Copy and Paste 2

JOI Spring Training Camp 2014/15
Original Statement / Submission Site

Problem Statement

One of the most important features of a text editor is copy and paste. JOI Corporation is developing a text editor that performs copy-and-paste operations extremely quickly. As an excellent programmer working for JOI Corporation, you have been assigned to test the core copy-and-paste functionality. The future of the company depends on this project, so you want to write an accurate and efficient program.

The detailed specification is as follows. Initially, the contents of the file are the string S. Then, N copy-and-paste operations are performed.

In the i-th operation, the substring between positions Ai and Bi is copied and inserted at position Ci of the original string.

A position x is the location immediately after the first x characters of the string. Thus, position 0 is the beginning of the string. For example, in the string copypaste, position 6 is between the characters a and s, while position 9 is after the final character e, that is, at the end of the string.

If the length of the string exceeds M after an operation, characters are deleted one by one from the right end until the length becomes exactly M.

Your task is to determine in advance the first K characters of the string obtained after all N operations, so that the editor can be tested.

Task

Given the integer K, the maximum string length M, the initial string S, the number N of operations, and the instructions for those operations, determine the first K characters of the resulting string.

Input

The input is given from standard input in the following format:

K M
S
N
A1 B1 C1
A2 B2 C2
...
AN BN CN

Output

Print one line containing the first K characters of the string obtained after all N operations.

Constraints

Subtasks

Subtask 1 [10 points]

Subtask 2 [90 points]

There are no additional constraints.

Sample Input 1

2 18
copypaste
4
3 6 8
1 5 2
4 12 1
17 18 0

Sample Output 1

ac

Explanation of Sample 1

In this example, the N = 4 copy-and-paste operations are performed as follows:

Therefore, the first K = 2 characters of the final string acyppypastoopyppyp are ac, which should be output.

Sample Input 2

6 100
jjooii
3
5 6 2
4 6 1
1 2 3

Sample Output 2

joioji