#P1017H. The Films

The Films

Description

In "The Man in the High Castle" world, there are mm different film endings.

Abendsen owns a storage and a shelf. At first, he has nn ordered films on the shelf. In the ii-th month he will do:

  1. Empty the storage.
  2. Put kimk_i \cdot m films into the storage, kik_i films for each ending.
  3. He will think about a question: if he puts all the films from the shelf into the storage, then randomly picks nn films (from all the films in the storage) and rearranges them on the shelf, what is the probability that sequence of endings in [li,ri][l_i, r_i] on the shelf will not be changed? Notice, he just thinks about this question, so the shelf will not actually be changed.

Answer all Abendsen's questions.

Let the probability be fraction PiP_i. Let's say that the total number of ways to take nn films from the storage for ii-th month is AiA_i, so PiAiP_i \cdot A_i is always an integer. Print for each month PiAi(mod998244353)P_i \cdot A_i \pmod {998244353}.

998244353998244353 is a prime number and it is equal to 119223+1119 \cdot 2^{23} + 1.

It is guaranteed that there will be only no more than 100100 different kk values.

The first line contains three integers nn, mm, and qq (1n,m,q1051 \le n, m, q \le 10^5, n+q105n+q\leq 10^5) — the number of films on the shelf initially, the number of endings, and the number of months.

The second line contains nn integers e1,e2,,ene_1, e_2, \ldots, e_n (1eim1\leq e_i\leq m) — the ending of the ii-th film on the shelf.

Each of the next qq lines contains three integers lil_i, rir_i, and kik_i (1lirin,0ki1051 \le l_i \le r_i \le n, 0 \le k_i \le 10^5) — the ii-th query.

It is guaranteed that there will be only no more than 100100 different kk values.

Print the answer for each question in a separate line.

Input

The first line contains three integers nn, mm, and qq (1n,m,q1051 \le n, m, q \le 10^5, n+q105n+q\leq 10^5) — the number of films on the shelf initially, the number of endings, and the number of months.

The second line contains nn integers e1,e2,,ene_1, e_2, \ldots, e_n (1eim1\leq e_i\leq m) — the ending of the ii-th film on the shelf.

Each of the next qq lines contains three integers lil_i, rir_i, and kik_i (1lirin,0ki1051 \le l_i \le r_i \le n, 0 \le k_i \le 10^5) — the ii-th query.

It is guaranteed that there will be only no more than 100100 different kk values.

Output

Print the answer for each question in a separate line.

Sample Input 1

6 4 4
1 2 3 4 4 4
1 4 0
1 3 2
1 4 2
1 5 2

Sample Output 1

6
26730
12150
4860

Sample Input 2

5 5 3
1 2 3 4 5
1 2 100000
1 4 4
3 5 5

Sample Output 2

494942218
13125
151632

Note

In the first sample in the second query, after adding 2m2 \cdot m films into the storage, the storage will look like this: {1,1,1,2,2,2,3,3,3,4,4,4,4,4}\{1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4\}.

There are 2673026730 total ways of choosing the films so that el,el+1,,ere_l, e_{l+1}, \ldots, e_r will not be changed, for example, [1,2,3,2,2][1, 2, 3, 2, 2] and [1,2,3,4,3][1, 2, 3, 4, 3] are such ways.

There are 21621602162160 total ways of choosing the films, so you're asked to print (2673021621602162160)mod  998244353=26730(\frac{26730}{2162160} \cdot 2162160) \mod 998244353 = 26730.