#include"bits/stdc++.h"
using namespace std;
using ll=long long;
#define S second
#define F first
const int md=1e4+7;
const int N=1<<17;
int n,k;
struct node{
ll c[22]={};
node(){
c[0]=1;
}
}tn[N*2];
node mrg(node&a,node&b){
node res;
res.c[0]=0;
// for(int i:a.c)cout<<i<<' ';
// cout<<endl;
// for(int i:b.c)cout<<i<<' ';
// cout<<endl;
for(int i=0;i<k;i++){
for(int j=0;j<=i;j++){
res.c[i]=(res.c[i]+a.c[j]*b.c[i-j]%md)%md;
// cout<<i<<' '<<j<<' '<<a.c[j]<<' '<<b.c[i-j]<<endl;
}
}
for(int i=0;i<=k;i++){
for(int j=k-i;j<=k;j++){
res.c[k]=(res.c[k]+a.c[i]*b.c[j]%md)%md;
}
}
// for(int i:res.c)cout<<i<<' ';
// exit(0);
return res;
}
void upd(int i,int a,int b){
i+=N;
tn[i].c[0]=b%md;
tn[i].c[1]=a%md;
while(i/=2)tn[i]=mrg(tn[i*2],tn[i*2+1]);
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cin>>n>>k;
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];
upd(i,a[i],b[i]);
}
int q;
cin>>q;
while(q--){
int i,x,y;
cin>>i>>x>>y;
// break;
upd(i,x,y);
cout<<tn[1].c[k]<<'\n';
}
// for(int i:tn[(2+N)/2].c)cout<<i<<' ';
}