#include using namespace std; typedef long long LL; templatevoid chmin(T &a,T b){a=min(a,b);} templatevoid chmax(T &a,T b){a=max(a,b);} template istream& operator>>(istream &is,vector &v){ for(auto &it:v)is>>it; return is; } const LL MOD = 1e9+7; #define SIZE 400000 #define L(v) (v*2+1) #define R(v) (v*2+2) struct A{ LL v[3][3]; }; struct B{ LL v[2][2]; }; struct C{ LL v[2][3]; }; #define mm(res,x,y,z) for(int i=0;i=MOD)res.v[i][j]-=MOD; } return res; } struct val{ A a; B b; C c; }; val getinitval(){ val res; for(int i=0;i<3;i++)for(int j=0;j<3;j++)res.a.v[i][j]=0; for(int i=0;i<2;i++)for(int j=0;j<2;j++)res.b.v[i][j]=0; for(int i=0;i<2;i++)for(int j=0;j<3;j++)res.c.v[i][j]=0; for(int i=0;i<3;i++)res.a.v[i][i]=1; for(int i=0;i<2;i++)res.b.v[i][i]=1; return res; } struct node { int bg, ed; val v; int len() { return ed - bg + 1; }; inline val getval() {return v;} inline void init(int b, int e) { bg = b, ed = e; } bool isleaf() { return bg == ed; } }mem[SIZE]; inline val combine(val l, val r) { return val{ mulmat(r.a,l.a), mulmat(l.b,r.b), addmat(l.c,mulmat(l.b,r.c,l.a)) }; } class segT { private: node *t; public: segT(int bg, int ed) :t(mem) { make_tree(bg, ed); } void update(int v) { node *p = t + v, *l = t + L(v), *r = t + R(v); if (!p->isleaf()) p->v = combine(l->getval(), r->getval()); } void set_A(int pos,A& x,int v = 0) { node *p = t + v, *l = t + L(v), *r = t + R(v); if (pos == p->bg&&pos == p->ed) { p->v.a=x; return; } if (pos <=min(pos, l->ed)) set_A(pos, x, L(v)); else set_A(pos, x, R(v)); update(v); } void set_B(int pos,B& x,int v = 0) { node *p = t + v, *l = t + L(v), *r = t + R(v); if (pos == p->bg&&pos == p->ed) { p->v.b=x; return; } if (pos <=min(pos, l->ed)) set_B(pos, x, L(v)); else set_B(pos, x, R(v)); update(v); } val get(int bg,int ed, int v = 0) { node *p = t + v, *l = t + L(v), *r = t + R(v); if (bg == p->bg&&ed == p->ed) { return p->getval(); } int m; val res=getinitval(); if (bg <= (m = min(ed, l->ed))) res=combine(res,get(bg, m, L(v))); if ((m = max(bg, r->bg)) <= ed) res=combine(res,get(m, ed, R(v))); return res; } void make_tree(int bg, int ed, int v = 0) { //cout<init(bg, ed); if (!p->isleaf()) { int m = (bg + ed) / 2; make_tree(bg, m, L(v)); make_tree(m+1, ed, R(v)); update(v); } else{ p->v=getinitval(); for(int j=0;j<2;j++) for(int k=0;k<3;k++) p->v.c.v[j][k]=6*bg+j*3+k; } } }; struct cww{cww(){ ios::sync_with_stdio(false);cin.tie(0); }}init; LL a0[3]; LL bn[2]; LL ai[3]; LL bi[2]; int main(){ int n; cin>>n; for(int i=0;i<3;i++)cin>>a0[i]; for(int i=0;i<2;i++)cin>>bn[i]; segT tree(0,n); int q; cin>>q; while(q--){ string s;int i; cin>>s>>i; if(s=="a"){ A v; for(int i=0;i<3;i++)for(int j=0;j<3;j++)cin>>v.v[i][j]; tree.set_A(i,v); } else if(s=="b"){ B v; for(int i=0;i<2;i++)for(int j=0;j<2;j++)cin>>v.v[i][j]; tree.set_B(i,v); } else if(s=="ga"){ if(i==0){ cout<