Colored painting sales

Each client buys a_i colored or b_i black-and-white paintings, and after each update count the sales with at least C colored buyers modulo 10007.

Hard8Dynamic programmingSegment treeCombinatoricsNo attempts yetTime limit4sMemory limit32 MB

Problem

Luka is an art dealer. He has NN clients and sells paintings to each of them.

Every client buys only colored paintings or only black and white paintings, never both kinds at once. Client ii buys at most aia_i colored paintings and at most bib_i black and white paintings, and whichever kind the client picks, the client buys at least one painting. Luka's stock is large enough that a client never has to settle for fewer paintings than requested.

Luka dislikes selling black and white paintings. If fewer than CC clients receive colored paintings, he ends up unhappy.

The clients keep revising the largest number of paintings they are willing to buy. After each revision, count the sales in which at least CC clients receive at least one colored painting.

Input

The first line contains two integers NN and CC (1N1000001 \le N \le 100000, 1C201 \le C \le 20).

The second line contains NN integers aia_i (1ai1091 \le a_i \le 10^9).

The third line contains NN integers bib_i (1bi1091 \le b_i \le 10^9).

The fourth line contains the number of revisions QQ (1Q1000001 \le Q \le 100000).

Each of the next QQ lines contains three integers PP, aPa_P and bPb_P (1PN1 \le P \le N, 1aP1091 \le a_P \le 10^9, 1bP1091 \le b_P \le 10^9). Client PP changes the largest number of colored paintings to aPa_P and the largest number of black and white paintings to bPb_P. Each revision stays in effect for every later revision.

Output

Print QQ lines. Line jj holds the number of sales right after the jj-th revision, modulo 1000710007.

Note

Two sales differ when some client buys a different kind of painting, or the same kind in a different quantity. One client therefore contributes aia_i possibilities when buying colored paintings and bib_i possibilities when buying black and white paintings. If CC is larger than NN, no sale meets the requirement and the answer is 0.