Under construction

Still being built. Things may change

A Plus B Problem

Time limit3sMemory limit1024 MB

Summary
After each single-digit change to the first or second row, report the requested digit of the sum's last n digits and how many digits of the machine change.
Level

Medium7 of 10

Topics
Segment tree, Math, Implementation
Solved
No attempts yet

Problem

JB got a machine that solves the A Plus B Problem, and he wants to know how it works. He heard that you are proficient in competitive programming and have learned many advanced data structures and algorithms, such as Link-Cut tree, Lagrange Inversion formula, Sweepline Mo, and so on. So he asks you to implement a program that solves the A Plus B Problem the same way the machine does.

The machine consists of 3×n3\times n digits. The digits of the first two rows can be changed arbitrarily, and the third row always equals the decimal sum of the first two rows. The third row keeps only the lowest nn digits, even if the sum has more than nn digits.

For example, when n=5n=5, the three rows can be 01234, 56789, 58023 or 56789, 58023, 14812.

To test your function, you are given qq queries. In the ii-th query, the cic_i-th digit of the rir_i-th row is changed to did_i (the digit may stay the same). JB has no time to check your answers, so he only asks you to find the cic_i-th digit of the third row after the query and how many digits of the machine change in that query.

Input

The first line contains two integers nn and qq (1≤n,q≤1061\le n, q\le10^6).

The second line contains a string of nn digits, representing the first row of the machine.

The third line contains a string of nn digits, representing the second row of the machine.

The next qq lines follow. The ii-th of them contains three integers rir_i, cic_i, and did_i (1≤ri≤21\le r_i \le 2, 1≤ci≤n1\le c_i\le n, 0≤di≤90\le d_i\le 9).

Output

Output qq lines. In the ii-th line, output two integers: the cic_i-th digit of the third row after the query, and how many digits of the machine change in the query.

Hint

In the example, the initial rows are 01234, 56789, 58023.

After the 1st query, the rows are 01234, 06789, 08023.

After the 2nd query, the rows are 01234, 01789, 03023.

After the 3rd query, the rows are 01234, 01289, 02523.

After the 4th query, the rows are 01234, 01239, 02473.

After the 5th query, the rows are 01234, 01234, 02468.

Examples1

  1. Example 1

    Input
    5 5
    01234
    56789
    2 1 0
    2 2 1
    2 3 2
    2 4 3
    2 5 4
    
    Expected output
    0 2
    3 2
    5 3
    7 3
    8 3