GGGGGGGGGGGGGG
#include <bits/stdc++.h>
#define ll long long
using namespace std;
unordered_map<long long,int> setV;
int a [10000005],b [10000005];
const ll p = 1e7 + 19;
struct opt {
int x,y,z;
} q [10000005];
ll qpow (ll a,int b) {
if (!b) return 1;
ll tmp = qpow (a,b >> 1);
tmp = (tmp * tmp) % p;
if (b & 1) {
return (tmp * a) % p;
}
return tmp;
}
int n,qn;
ll sum = 0; //全部的和
ll ji = 1; //全部的积
ll fu = 0; //全部赋值为什么
ll fuT = -1;//什么时候全部赋值的
ll add = 0;
inline ll mod (ll x) {
return ((x % p) + p) % p;
}
inline ll getV (int i) {
if (setV.find (i) != setV.end ()) {
return setV [i] * ji + add;
}
return fu * ji + add;
}
ll ans = 0;
inline void solve (int i,int t) {
int ty = q [i].x;
int y = q [i].y;
int z = q [i].z;
if (ty == 1) { //设置ai
//z = ji * v + add
long long ni = qpow (ji,p - 2);
sum += z - getV (y);
sum %= p;
setV [y] = (mod (z - add) * ni) % p;
}
if (ty == 2) { //全部加y
sum += (y * n) % p;
sum %= p;
add += y;
}
if (ty == 3) {
sum *= y;
add *= y;
ji *= y;
sum %= p;
add %= p;
ji %= p;
}
if (ty == 4) {
sum = (y * n) % p;
ji = 1;
fu = y;
fuT = t;
add = 0;
setV.clear ();
}
if (ty == 5) { //询问y
ans += getV (y);
ans = mod (ans);
}
if (ty == 6) {
ans += sum;
ans = mod (ans);
}
}
int main () {
#ifndef ONLINE_JUDGE
freopen ("shit.txt","r",stdin);
#endif
ios::sync_with_stdio (false);
cin >> n >> qn;
for (int i = 1;i <= qn;++ i) {
cin >> q [i].x;
if (2 <= q [i].x && q [i].x <= 5) {
cin >> q [i].y;
if (q [i].x != 5) {
q [i].y %= p;
}
}
if (q [i].x == 1) {
cin >> q [i].y >> q [i].z;
q [i].z %= p;
}
}
int t;cin >> t;
for (int i = 1;i <= t;++ i) cin >> a [i] >> b [i];
int tt = 0;
for (int i = 1;i <= t;++ i) {
for (int j = 1;j <= qn;++ j) {
int k = ((a [i] + j * b [i]) % qn) + 1;
solve (k,tt);
++ tt;
}
}
cout << ans << endl;
return 0;
}