#P9811. Hello World 3 Pro Max
Hello World 3 Pro Max
Hello World 3 Pro Max
Problem Description
Once upon a time, Markyyz invented a problem named "Hello World". Later, Markyyz invented a problem named "Hello World 2", which is a harder version of "Hello World". Two thousand years later, SPY invented a problem named "Hello World 3", which is an even harder version of "Hello World". Now, SPY is inventing a problem named "Hello World 3 Pro Max", which is ... SPY has a string of length consisting of lowercase letters: . The string is generated randomly in the following way: for each character in , it is independently generated from the set with possibilities . In other words, there is a probability of for the letter , for the letter , and so on. It is guaranteed that sum of 's is equal to 1. Initially, each character of string is unknown. Then, SPY will perform operations of two types: Type 1: , which means SPY determines that the character is . In this problem, the characters in string are indexed starting from 1, so can be expressed as . It is guaranteed that no two operations will conflict with each other. Type 2: , which means SPY wants to know the expected number of subsequences equals to in the substring , modulo . Here, means the substring of starting at index and ending at index (formally ). After each operation of Type 2, you should answer the query by outputting the expected number on a separate line, modulo .
Input
There are multiple tests. The first line of input consists a single integer , representing the number of test cases. In each test case, the following lines provide the details: The first line consists a single integer , representing the length of string . The second line contains 7 integers . Let be the sum of these values. The possibilities of the letters are defined as . The third line contains a single integer , representing the number of operations. The next lines describe the operations, each line specifying the type and parameters of the operation. It is guaranteed that sum of in all test cases will not exceed , sum of in all test cases will not exceed .
Output
After every operation of Type 2, output the expected number on a single line, modulo .
Sample Input
1
11
1 1 1 1 1 1 1
16
1 1 h
2 1 11
2 2 11
1 2 e
1 3 l
1 4 l
1 5 l
2 1 11
1 6 o
1 7 w
2 2 11
1 8 o
1 9 r
1 10 l
1 11 d
2 1 11
Sample Output
667718262
953066461
937670535
0
3
Source
2023“钉耙编程”中国大学生算法设计超级联赛(2)