#ABC262H. [ABC262Ex] Max Limited Sequence

[ABC262Ex] Max Limited Sequence

Score : 600600 points

Problem Statement

Find the number, modulo 998244353998244353, of integer sequences A=(A1,,AN)A = (A_1, \dots, A_N) of length NN that satisfy all of the following conditions:

  • 0AiM0 \leq A_i \leq M for all ii such that 1iN1 \leq i \leq N.
  • The maximum value of ALj,,ARjA_{L_j}, \dots, A_{R_j} is XjX_j for all jj such that 1jQ1 \leq j \leq Q.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1M<9982443531 \leq M \lt 998244353
  • 1Q2×1051 \leq Q \leq 2 \times 10^5
  • 1LiRiN(1iQ)1 \leq L_i \leq R_i \leq N \, (1 \leq i \leq Q)
  • 1XiM(1iQ)1 \leq X_i \leq M \, (1 \leq i \leq Q)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM QQ

L1L_1 R1R_1 X1X_1

\vdots

LQL_Q RQR_Q XQX_Q

Output

Print the answer.

3 3 2
1 2 2
2 3 3
5

$A = (0, 2, 3), (1, 2, 3), (2, 0, 3), (2, 1, 3), (2, 2, 3)$ satisfy the conditions.

1 1 1
1 1 1
1
6 40000000 3
1 4 30000000
2 6 20000000
3 5 10000000
135282163