#P6553. Strings of Monody
Strings of Monody
Background

LGD is a little dinosaur who likes Monody.
Based on the music of Monody, he built a model called the "String of Monody". For short, SoM (String of Monody).
Problem Description
A "String of Monody" is a string consisting only of , , and . In each operation, LsWn takes a substring with left endpoint and right endpoint (note that the first character has index , and the last character has index ), and replaces it with a newly given substring. After the replacement, you need to answer queries about the whole string:
- The number of 's.
- The sum of all digits in the whole string.
- The product of all digits in the whole string.
All outputs should be taken modulo .
Input Format
The first line contains a string.
The second line contains an integer , meaning there are operations.
In the next lines, each line contains two integers , followed by a string of length , meaning to change the substring into this string.
Output Format
Output lines. Each line contains integers, representing the queries after each modification.
114514
3
1 3 111
3 4 44
4 4 5
4 13 20
3 15 64
3 16 80
Hint
Explanation for Sample 1:
After the first operation, the string becomes 111514. The number of 's is , the sum is , and the product is $1\times 1\times 1\times 1\times 5\times 1\times 4=20$.
After the second operation, the string becomes 114414.
After the third operation, the string becomes 114514.
Let the initial string length be .
For of the testdata, .
For of the testdata, .
For all testdata, , , and .
Translated by ChatGPT 5