#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define endl '\n'
#define mod 10007
#define int long long
const int N=(1ll<<17);
vector<int> tree[2*N];
vector<int> merg(vector<int> a, vector<int> b) {
if(a.empty()) a.resize(22, 0), a[0]=1;
if(b.empty()) b.resize(22, 0), b[0]=1;
vector<int> ans;
ans.resize(22, 0);
// ans[0]=1;
for(int i = 0;i <= 21;i++) {
for(int j=0;j<= 21;j++) {
ans[min(21ll, i+j)]+=(a[i]*b[j])%mod;
ans[min(21ll, i+j)]%=mod;
}
}
return ans;
}
void update(int x, int y, int j) {
x+=N;
tree[x].resize(22, 0);
tree[x][0]=j, tree[x][1]=y;
while(x>1) {
x/=2;
tree[x]=merg(tree[2*x], tree[2*x+1]);
}
}
// vector<int> query(int l, int r, int ql, int qr, int v) {
// if(ql<=l&&r<=qr) return tree[v];
// if(r<ql||l>qr) return {};
// int mid=(l+r)/2;
// return merg(query(l, mid, ql, qr, 2*v), query(mid+1, r, ql, qr, 2*v+1));
// }
main()
{
cin.tie(0) -> sync_with_stdio(0);
int n, c;
cin >> n >> c;
int a[n+1]={}, b[n+1]={};
for(int i=1;i <= n;i++) cin >> a[i];
for(int i=1;i <= n;i++) cin >> b[i];
for(int i = 1;i <= n;i++) update(i, a[i]%mod, b[i]%mod);
int q;
cin >> q;
while(q--) {
int p;
cin >> p;
int x, y;
cin >> x >> y;
a[p]=x, b[p]=y;
update(p, x, y);
// vector<int> s=query(0, N-1, 1, n, 1);
vector<int> s=tree[1];
int ans=0;
for(int i=c;i<=21;i++) ans+=s[i]%mod, ans%=mod;
cout << ans << endl;
}
}