Putata is dreaming that he got lost in a phantom grid world of size $$$n \times m$$$. The rows and columns of the grid are numbered from $$$0$$$ to $$$n - 1$$$ and $$$0$$$ to $$$m - 1$$$, respectively. Putata has no idea how to escape from the phantom world, so he decides to walk randomly. Assuming Putata is now at $$$(x, y)$$$, he will:
You need to perform $$$q$$$ operations. Each operation is one of the following:
Please write a program to answer his questions.
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$3 \leq n \leq 10^5$$$, $$$3 \leq m \leq 5$$$) denoting the size of the phantom grid world.
In the next $$$n$$$ lines, the $$$i$$$-th line contains $$$m$$$ integers $$$\ell(i - 1, 0), \ell(i - 1, 1), \ldots, \ell(i - 1, m - 1)$$$ ($$$1 \leq i \leq n$$$, $$$1 \leq \ell(\cdot, \cdot) \leq 100$$$).
In the next $$$n$$$ lines, the $$$i$$$-th line contains $$$m$$$ integers $$$r(i - 1, 0), r(i - 1, 1), \ldots, r(i - 1, m - 1)$$$ ($$$1 \leq i \leq n$$$, $$$1 \leq r(\cdot, \cdot) \leq 100$$$).
In the next $$$n$$$ lines, the $$$i$$$-th line contains $$$m$$$ integers $$$u(i - 1, 0), u(i - 1, 1), \ldots, u(i - 1, m - 1)$$$ ($$$1 \leq i \leq n$$$, $$$1 \leq u(\cdot, \cdot) \leq 100$$$).
In the next $$$n$$$ lines, the $$$i$$$-th line contains $$$m$$$ integers $$$d(i - 1, 0), d(i - 1, 1), \ldots, d(i - 1, m - 1)$$$ ($$$1 \leq i \leq n$$$, $$$1 \leq d(\cdot, \cdot) \leq 100$$$).
It is guaranteed that $$$\ell(i, j) + r(i, j) + u(i, j) + d(i, j) = 100$$$ holds for all pairs of $$$(i, j)$$$ where $$$0 \leq i \lt n$$$ and $$$0 \leq j \lt m$$$.
The next line contains a single integer $$$q$$$ ($$$1 \leq q \leq 3 \cdot 10^4$$$) denoting the number of operations.
Each of the next $$$q$$$ lines describes an operation in the format described in the statement above.
For each test query, print a single line containing an integer: the expected number of steps that Putata will take when he reaches the target position $$$(\mathit{tx}, \mathit{ty})$$$ for the first time.
More precisely, assuming the reduced fraction of the answer is $$$\frac{p}{q}$$$, you should output the minimum non-negative integer $$$r$$$ such that $$$q \cdot r \equiv p \pmod{10^9 + 7}$$$. You may safely assume that such $$$r$$$ always exists in all test cases.
4 31 2 34 5 67 8 910 11 1223 24 2526 27 2829 30 3132 33 3410 11 1213 14 1516 17 1819 20 2166 63 6057 54 5148 45 4239 36 3342 0 1 1 12 0 0 3 21 1 1 25 25 25 252 0 0 3 2
76426175 344136684 555192113
| Name |
|---|


