QOJ.ac

QOJ

时间限制: 1 s 内存限制: 256 MB 总分: 100

#14624. Mathematical Calculation

统计

Xiao Dou has a number $x$, initially $1$. Xiao Dou performs $Q$ operations, which are of two types:

  1. $m$: $x = x \times m$, output $x \pmod{mod}$;
  2. $pos$: $x = x / (\text{the number multiplied in the } pos\text{-th operation})$. (It is guaranteed that the $pos$-th operation is of type 1, and each type 1 operation is divided at most once). Output $x \pmod{mod}$.

Input

There are $t$ test cases ($t \le 5$). For each test case, the first line contains two integers $Q$ and $mod$ ($Q \le 100000, mod \le 1000000000$). The next $Q$ lines each contain an operation type and the operation number or the number to be multiplied (it is guaranteed that all inputs are valid).

Output

For each operation, output the value of $x \pmod{mod}$ after the operation is performed.

Examples

Input 1

1
10 1000000000
1 2
2 1
1 2
1 10
2 3
2 4
1 6
1 7
1 12
2 7

Output 1

2
1
2
20
10
1
6
42
504
84

Constraints

For 20% of the data, $1 \le Q \le 500$. For 100% of the data, $1 \le Q \le 100000$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.