Under construction

Still being built. Things may change

Substring Sort

Time limit2sMemory limit1024 MB

Summary
Each query sorts the three substrings A[l..r], B[l..r], and C[l..r] and writes them back in sorted order. Print the final A, B, and C.
Level

Hard8 of 10

Topics
String, Segment tree, String matching
Solved
No attempts yet

Problem

In this problem, all strings are indexed from 1. sis_i is the iith character of string ss, and sl..rs_{l..r} is the substring slsl+1⋯srs_l s_{l+1} \cdots s_r.

You are given three strings AA, BB, and CC, each of length NN. You must process QQ queries in order. Each query gives two integers ll and rr, and you perform these steps:

  1. Copy the substrings Al..rA_{l..r}, Bl..rB_{l..r}, and Cl..rC_{l..r}. Call the copies xx, yy, and zz.
  2. Sort [x,y,z][x, y, z] in lexicographical order. Call the sorted result [x′,y′,z′][x', y', z'].
  3. Replace Al..rA_{l..r} with x′x', Bl..rB_{l..r} with y′y', and Cl..rC_{l..r} with z′z'.

Find the final values of AA, BB, and CC after all queries.

Input

The first line has two integers NN and QQ (1≤N≤100 0001 \le N \le 100\,000, 1≤Q≤100 0001 \le Q \le 100\,000). The next three lines contain the strings AA, BB, and CC, each of length NN, made of lowercase letters. Each of the next QQ lines contains two integers ll and rr (1≤l≤r≤N1 \le l \le r \le N).

Output

Print three lines with the final values of AA, BB, and CC, in that order.

Examples3

  1. Example 1

    Input
    5 2
    icpca
    siaja
    karta
    2 4
    1 5
    
    Expected output
    iarta
    kiaja
    scpca
    
  2. Example 2

    Input
    6 6
    aabbcc
    bcacab
    cbcaba
    1 1
    2 2
    3 3
    4 4
    5 5
    6 6
    
    Expected output
    aaaaaa
    bbbbbb
    cccccc
    
  3. Example 3

    Input
    3 1
    aba
    aab
    aac
    1 3
    
    Expected output
    aab
    aac
    aba