George's Grass
题号:NC230981
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Besides George Plover's house stands a farm. The farm can be described as an matrix. The growth rate of weed in row i and column j is denoted as . In this problem, two arrays and will be given. And for all , , .
The growth rate indicates that the weed will grow units every second. At the moment 0, there is no weed on the farm.
George will use mower q times, where the i-th use occurs at the moment t_i. Each use of the mower completely removes weeds in a row or a column.
George wonders how many units of weed he will remove.
The answer might be very large, so please output the desired answer modulo .

输入描述:

The first line contains two integers n and m.
The second line contains n integers, where the i-th integer is A_i.
The third line contains m integers, where the j-th integer is B_j.
The next line contains an integer q.
Each of the next q lines contains three integers.
1 x t: George clears the weeds in row x at the moment t.

2 y t: George clears the weeds in column y at the moment t.

, .
It is guaranteed that , , and t is strictly increasing with lines.


输出描述:

Output one integer indicating the answer modulo .
示例1

输入

复制
2 2
1 1
1 1
3
1 1 1
2 1 3
2 2 5

输出

复制
16
示例2

输入

复制
2 3
1 2
3 4 5
3
1 1 1
2 1 2
2 3 3

输出

复制
67

说明