#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 10007;
int n, c, q;
int a[100000], b[100000];
int st[1 << 18][20], stot[1 << 18];
const int off = 1 << 17;
void stMerge(int v, int l, int r) {
int *s = st[v];
int *a = st[l];
int *b = st[r];
REP(i, c) {
s[i] = 0;
REP(j, i + 1) s[i] += a[j] * b[i - j];
s[i] %= MOD;
}
stot[v] = stot[l] * stot[r] % MOD;
}
void stBuild() {
REP(i, n) {
st[off + i][0] = b[i];
st[off + i][1] = a[i];
stot[off + i] = (a[i] + b[i]) % MOD;
}
for (int i = n; i < off; ++i) {
st[off + i][0] = 1;
stot[off + i] = 1;
}
for (int i = off - 1; i >= 1; --i) {
stMerge(i, i << 1, (i << 1) | 1);
}
}
void stUpdate(int pos, int a, int b) {
pos += off;
st[pos][0] = b;
st[pos][1] = a;
stot[pos] = a + b;
if (stot[pos] >= MOD) stot[pos] -= MOD;
for (pos >>= 1; pos >= 1; pos >>= 1) {
stMerge(pos, pos << 1, (pos << 1) | 1);
}
}
int main() {
scanf("%d%d", &n, &c);
REP(i, n) scanf("%d", a + i), a[i] %= MOD;
REP(i, n) scanf("%d", b + i), b[i] %= MOD;
stBuild();
scanf("%d", &q);
REP(query, q) {
int x, y, z;
scanf("%d%d%d", &x, &y, &z), --x, y %= MOD, z %= MOD;
stUpdate(x, y, z);
int ans = stot[1];
REP(i, c) ans -= st[1][i];
ans %= MOD;
if (ans < 0) ans += MOD;
printf("%d\n", ans);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBtcCBtYWtlX3BhaXIKI2RlZmluZSBSRVAoaSwgbikgZm9yIChpbnQgaSA9IDA7IGkgPCAoaW50KShuKTsgKytpKQp0eXBlZGVmIGxvb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