Besides George Plover's house stands a farm. The farm can be described as an matrix. The growth rate of weed in row
and column
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
, there is no weed on the farm.
George will use mower times, where the
-th use occurs at the moment
. 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
and
.
The second line containsintegers, where the
-th integer is
.
The third line containsintegers, where the
-th integer is
.
The next line contains an integer.
Each of the nextlines contains three integers.
![]()
![]()
: George clears the weeds in row
at the moment
.
![]()
![]()
: George clears the weeds in column
at the moment
.
,
.
It is guaranteed that,
,
and
is strictly increasing with lines.
Output one integer indicating the answer modulo.