#P17898. [ICPC 2026 Nanchang I] Legacy Code
[ICPC 2026 Nanchang I] Legacy Code
Problem Description
You have a piece of legacy code:
$$\begin{array}{l} \textbf{for } t = 1 \textbf{ to } k \textbf{ do} \\ \qquad a_{x_1} \leftarrow (a_{u_1} \times a_{v_1}) \bmod MOD \\ \qquad a_{x_2} \leftarrow (a_{u_2} \times a_{v_2}) \bmod MOD \\ \qquad a_{x_3} \leftarrow (a_{u_3} \times a_{v_3}) \bmod MOD \\ \qquad \vdots \\ \qquad a_{x_m} \leftarrow (a_{u_m} \times a_{v_m}) \bmod MOD \\ \textbf{end for} \end{array}$$where and for .
Given the initial values of the variables , compute their final values after the loop runs times. You need to answer such queries.
Input Format
The first line contains three integers , and (, , ).
The next lines each contain three integers , , ().
Each of the next lines represents a query. Each query contains integers:
- the number of iterations (),
- the initial values of the variables ().
Output Format
For each query, output a single line containing integers --- the final values of after executing the code, each modulo .
7 8 4
3 1 2
4 3 3
5 6 7
7 1 3
2 2 2
6 6 2
1 5 6
7 7 7
1 2 1 1 1 1 1 1
2 1 2 3 4 5 6 7
3 1 1 0 1 0 1 0
100 11 45 14 19 19 8 10
1 1 2 4 1 1 16
36864 16 4032 16257024 96 384 227524445
0 1 1 1 0 1 1
244858606 337827833 584144609 343808937 412777304 279017446 926699892