#P4588. [TJOI2018] 数学计算

[TJOI2018] 数学计算

Description

Xiaodou now has a number xx, initially 11. There are QQ operations of two types:

1 m: set xx to x×mx \times m, then output xmodMx \bmod M.

2 pos: set xx to xx divided by the number multiplied in the pospos-th operation (it is guaranteed that the pospos-th operation is of type 1, and each type 1 operation will be divided at most once), then output xmodMx \bmod M.

Input Format

There are tt test cases.

For each test case, the first line contains two integers Q,MQ, M.

The next QQ lines each contain an operation, formatted as either 1 m or 2 pos (all inputs are guaranteed to be valid).

Output Format

For each operation, output one line containing the value of xmodMx \bmod M after executing the operation.

1
10 1000000000
1 2
2 1
1 2
1 10
2 3
2 4
1 6
1 7
1 12
2 7
2
1
2
20
10
1
6
42
504
84

Hint

For 20%20\% of the testdata, 1Q5001 \le Q \le 500.

For 100%100\% of the testdata, 1Q1051 \le Q \le 10^5, t5t \le 5, 1<M1091 \lt M \le 10^9, 0<m1090 < m \leq 10^9.

Translated by ChatGPT 5