{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eThere is an infinite 3D value grid space $a_{i,j,k}$. Initially, for $ \\forall i,j,k \\ a_{i,j,k}$ \u003d 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. \u003cbr\u003eWe want to know $a_{0,0,0} mod \\ 998244353$ after $n$ seconds.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"There are several test cases in the input file.\u003cbr\u003eIn 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)$. \u003cbr\u003eThe $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)$\u003cbr\u003eIt 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."}},{"title":"Output","value":{"format":"HTML","content":"For each test case, print a single line containing an integer, denoting the value of $a_{0,0,0} \\ mod \\ 998244353$ after $n$ seconds.\u003cbr\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e1 1 1 1 2 6\r\n0 0 2\r\n0 1 3\r\n0 2 4\r\n1 0 4\r\n1 1 2\r\n2 0 2\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e9216\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}