Little H is a diligent middle school student whose dream is to enter his favorite university to study computer science. To achieve this goal, he has been studying the basics of informatics competitions since he was young.
Today, Little H learned about the square operation. To test whether he has mastered it, he decided to create a problem for himself. Little H has a sequence of length $N$, $\{X_1, X_2, \dots, X_N\}$. Little H will occasionally take a continuous interval $[l, r]$ from the sequence and change each number in it to the result of its square modulo $p$, that is: $$\forall i \in [l, r], X_i \leftarrow (X_i \times X_i) \bmod p$$ where $p$ is a given number. To check if his calculations are correct, Little H also wants to know the sum of all numbers in a continuous interval $[l, r]$ of the sequence from time to time.
However, Little H does not have the standard answers now. Therefore, he asks for your help, hoping you can write a program to help him calculate the sum of the numbers in the interval he wants to know each time.
Input
The first line contains three integers $N, M, p$, representing the length of the sequence, the total number of square operations and query operations, and the modulus used in the square operation, respectively.
The next line contains $N$ integers representing the initial sequence $\{X_1, X_2, \dots, X_N\}$.
The next $M$ lines each contain three integers $op, l, r$. Here $op$ represents the type of operation. If $op = 0$, it represents a square operation on the interval $[l, r]$; if $op = 1$, it represents a query operation on the interval $[l, r]$.
Output
For each query operation, output one line representing the sum of the numbers in that interval. Note: The answer is not taken modulo any number.
Constraints
For 100% of the data, $\forall i, X_i \in [0, p)$, $l, r \in [1, N]$. The ranges of $N, M, p$ are detailed in the table below:
| ID | $N$ | $M$ | $p$ |
|---|---|---|---|
| 1 | $\le 1,000$ | $\le 1,000$ | $= 233$ |
| 2 | $= 2332$ | ||
| 3 | $\le 100,000$ | $\le 100,000$ | $= 5$ |
| 4 | $= 8192$ | ||
| 5 | $\le 100,000$ | $\le 100,000$ | $= 23$ |
| 6 | $= 45$ | ||
| 7 | $= 37$ | ||
| 8 | $\le 55,000$ | $\le 55,000$ | $= 4185$ |
| 9 | $= 5850$ | ||
| 10 | $= 2975$ | ||
| 11 | $= 2542$ | ||
| 12 | $= 2015$ | ||
| 13 | $\le 60,000$ | $\le 60,000$ | $= 2003$ |
| 14 | $\le 65,000$ | $\le 65,000$ | $= 2010$ |
| 15 | $\le 70,000$ | $\le 70,000$ | $= 4593$ |
| 16 | $\le 75,000$ | $\le 75,000$ | $= 4562$ |
| 17 | $\le 80,000$ | $\le 80,000$ | $= 1034$ |
| 18 | $\le 85,000$ | $\le 85,000$ | $= 5831$ |
| 19 | $\le 90,000$ | $\le 90,000$ | $= 9905$ |
| 20 | $\le 100,000$ | $\le 100,000$ | $= 9977$ |
Examples
Input 1
3 3 11 1 2 3 1 1 3 0 1 3 1 1 3
Output 1
6 14
Input 2
3 3 3 0 1 2 1 1 3 0 1 3 1 1 3
Output 2
3 2