#include #include #include #include #define repeat(i,n) for (int i = 0; (i) < int(n); ++(i)) using ll = long long; using namespace std; const int mod = 1e9+7; template using matrix = array,H>; template matrix operator * (matrix const & a, matrix const & b) { matrix c = {}; repeat (y,A) { repeat (z,B) { repeat (x,C) { c[y][x] = (c[y][x] + a[y][z] *(ll) b[z][x]) % mod; } } } return c; } template array operator * (matrix const & a, array const & b) { array c = {}; repeat (y,H) { repeat (z,W) { c[y] = (c[y] + a[y][z] *(ll) b[z]) % mod; } } return c; } template matrix operator + (matrix const & a, matrix const & b) { matrix c; repeat (y,H) { repeat (x,W) { c[y][x] = (a[y][x] + b[y][x]) % mod; } } return c; } template array operator + (array const & a, array const & b) { array c; repeat (i,N) { c[i] = (a[i] + b[i]) % mod; } return c; } template matrix matrix_zero() { return {}; } template matrix matrix_unit() { matrix a = {}; repeat (i,N) a[i][i] = 1; return a; } template struct segment_tree { // on monoid int n; vector a; function append; // associative T unit; // unit segment_tree() = default; segment_tree(int a_n, T a_unit, function a_append) { n = 1; while (n < a_n) n *= 2; a.resize(2*n-1, a_unit); unit = a_unit; append = a_append; } template void point_update(int i, F func) { // 0-based a[i+n-1] = func(a[i+n-1]); for (i = (i+n)/2; i > 0; i /= 2) { a[i-1] = append(a[2*i-1], a[2*i]); } } T point_get(int i) { return range_concat(i, i+1); } T range_concat(int l, int r) { // 0-based, [l, r) T lacc = unit, racc = unit; for (l += n, r += n; l < r; l /= 2, r /= 2) { if (l % 2 == 1) lacc = append(lacc, a[(l ++) - 1]); if (r % 2 == 1) racc = append(a[(-- r) - 1], racc); } return append(lacc, racc); } }; struct range_t { matrix A; matrix B; matrix S; }; int main() { int n; cin >> n; array a0; repeat (i,3) cin >> a0[i]; array bn; repeat (i,2) cin >> bn[i]; segment_tree segtree(n+1, (range_t) { matrix_unit(), matrix_unit(), matrix_zero() }, [&](range_t const & l, range_t const & r) { range_t m; m.A = r.A * l.A; m.B = l.B * r.B; m.S = l.S + l.B * r.S * l.A; return m; }); repeat (i,n+1) { segtree.point_update(i, [&](range_t m) { repeat (y,2) repeat (x,3) m.S[y][x] = 6*i + 3*y+x; return m; }); } int query; cin >> query; while (query --) { string type; int i; cin >> type >> i; if (type == "a") { segtree.point_update(i, [](range_t m) { repeat (y,3) repeat (x,3) cin >> m.A[y][x]; return m; }); } else if (type == "b") { segtree.point_update(i, [](range_t m) { repeat (y,2) repeat (x,2) cin >> m.B[y][x]; return m; }); } else if (type == "ga") { range_t m = segtree.range_concat(0, i); array ai = m.A * a0; cout << ai[0] << ' ' << ai[1] << ' ' << ai[2] << endl; } else if (type == "gb") { range_t l = segtree.range_concat(0, i+1); range_t r = segtree.range_concat(i+1, n+1); array bi = r.B * bn + r.S * l.A * a0; cout << bi[0] << ' ' << bi[1] << endl; } } return 0; }