Under construction

Still being built. Things may change

Binary String

Time limit2sMemory limit512 MB

Summary
Given a binary string and m operations that insert complements of substrings after position y, print the first k characters of the final string.
Level

Medium6 of 10

Topics
String, Simulation, Recursion
Solved
No attempts yet

Problem

You are given a binary string SS of length nn, consisting only of 0 and 1.

The indices of SS start from 1. S[a:b]S[a : b] denotes the substring of SS from index aa to index bb, inclusive.

You apply the following insertion operation mm times. Each operation takes two integers x≤yx \le y, and the values of xx and yy may differ between operations.

  • The inserted string is the complement of S[x:y]S[x : y], meaning every 0 becomes 1 and every 1 becomes 0.
  • The string is inserted immediately after the yy-th character of SS. After the insertion, the length of SS grows by y−x+1y - x + 1.
  • SS is updated after each operation. The next operation uses the updated SS.

The goal is to find the first kk characters of the final SS after all mm operations.

For example, let S=01010110S = 01010110, n=8n = 8, m=2m = 2, k=12k = 12, and apply the operations (x=2,y=4)(x = 2, y = 4) and (x=3,y=5)(x = 3, y = 5) in order. The first operation inserts the complement of S[2:4]=101S[2 : 4] = 101, which gives S = 01010100110 (the bold part is the inserted text). The second operation inserts the complement of S[3:5]=010S[3 : 5] = 010, which gives S = 01010101100110. Since k=12k = 12, the answer is the first 12 characters, 010101011001.

Input

The first line contains the number of test cases TT (1≤T≤101 \le T \le 10).

The first line of each test case contains nn, mm, and kk, separated by spaces.

The second line contains the binary string of length nn.

Each of the next mm lines contains two integers xix_i and yiy_i. It is guaranteed that 1≤xi≤yi≤1 \le x_i \le y_i \le min(the length of SS just before the ii-th operation, 101210^{12}).

Also, kk does not exceed the smaller of the length of the final SS and 10610^6.

Output

For each test case, print the string of length kk on one line.

Hint

  • Case 2: 1010 becomes 10010. Since k=4k = 4, only the first 4 characters are printed.
  • Case 3: 10101100 becomes 1001101100, and then 10011011110010000. Since k=16k = 16, only the first 16 characters are printed.

Examples1

  1. Example 1

    Input
    3
    8 2 12
    01010110
    2 4
    3 5
    4 1 4
    1010
    1 1
    8 2 16
    10101100
    1 2
    2 8
    
    Expected output
    010101011001
    1001
    1001101111001000