#P6712. sakura

    ID: 5569 远端评测题 4000ms 256MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛

sakura

Problem Description

There is an infinite 3D value grid space $a_{i,j,k}$. Initially, for $ \forall i,j,k \ a_{i,j,k}$ = 1. First, we change the value of $m$ grids. In the $i-th$ operation, we change the value of $a_{n, x_i, y_i}$ from 1 to $v_i$. Then the grid in the space will change every second. The value of the grid $a_{i,j,k}$ will change to $a_{i+1,j+p,k} ^ {t1} \times a_{i+1,j,k+q} ^ {t2} \times a_{i+1,j,k} \times a_{i,j,k}$ for every second.
We want to know $a_{0,0,0} mod \ 998244353$ after $n$ seconds.

Input

There are several test cases in the input file.
In the each test case, the first line contains six integers $t1,t2,p,q,n,m (1 \leq t1,t2,p,q,n \leq 10^9, 1 \leq m \leq 10 ^ 5)$.
The $i-th$ line in the next $m$ lines contains three integers $x_i, y_i, v_i (0 \leq x_i,y_i \leq 10^9, \ 1 \leq v_i \leq 10^9)$
It is guaranteed that $\sum m \leq 2*10^5$ and for $ \forall i,j (\ i \neq j) ; \ x_i \neq x_j \ or \ y_i \neq y_j$ in each test case.

Output

For each test case, print a single line containing an integer, denoting the value of $a_{0,0,0} \ mod \ 998244353$ after $n$ seconds.

1 1 1 1 2 6 0 0 2 0 1 3 0 2 4 1 0 4 1 1 2 2 0 2
9216