#pragma GCC optimize ("O3") #pragma GCC target ("avx") #include using namespace std; const long long mod = 1e9 + 7; template struct Matrix { long long a[H][W] = {}; static Matrix I() { Matrix res; for (int i = 0; i < H; i++) res[i][i] = 1; return res; } Matrix operator+(const Matrix &b) const { Matrix s; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { s.a[i][j] = a[i][j] + b.a[i][j]; if (s.a[i][j] >= mod) s.a[i][j] -= mod; } } return s; } template Matrix operator*(const Matrix &b) const { Matrix s; const long long modl = 8 * mod * mod; for (int i = 0; i < H; i++) { for (int k = 0; k < W; k++) { for (int j = 0; j < N; j++) { s[i][j] += a[i][k] * b.a[k][j]; if (s[i][j] >= modl) s[i][j] -= modl; } } for (int j = 0; j < N; j++) s[i][j] %= mod; } return s; } long long *operator[](int i) { return a[i]; } }; const int N = 1 << 17; struct Tuple { Matrix<3, 3> A; Matrix<2, 2> B; Matrix<2, 3> S; Tuple() { A = Matrix<3, 3>::I(); B = Matrix<2, 2>::I(); } Tuple(Matrix<3, 3> A, Matrix<2, 2> B, Matrix<2, 3> S) : A(A), B(B), S(S) {} Tuple operator*(const Tuple &r) const { return Tuple(r.A * A, B * r.B, S + B * r.S * A); } }; Tuple seg[N * 2]; void build() { for (int k = 0; k < N; k++) { for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { seg[k + N].S[i][j] = k * 6 + i * 3 + j; } } for (int i = 0; i < 3; i++) seg[k + N].A[i][i] = 1; for (int i = 0; i < 2; i++) seg[k + N].B[i][i] = 1; } for (int k = N - 1; k > 0; k--) { seg[k] = seg[k * 2 + 0] * seg[k * 2 + 1]; } } void update(int k) { k += N; while (k > 1) { k >>= 1; seg[k] = seg[k * 2 + 0] * seg[k * 2 + 1]; } } Tuple query(int l, int r) { Tuple L, R; for (l += N, r += N; l < r; l >>= 1, r >>= 1) { if (l & 1) L = L * seg[l++]; if (r & 1) R = seg[--r] * R; } return L * R; } // I6 A0 A1 | A2 A3 A4 A5 // I5 A0 A1 | A2 A3 A4 // I4 A0 A1 | A2 A3 // I3 A0 A1 | A2 // ------------------------------- // I2 A0 A1 // I1 A0 int main() { int n; cin >> n; Matrix<3, 1> va; Matrix<2, 1> vb; for (int i = 0; i < 3; i++) scanf("%lld", &va[i][0]); for (int i = 0; i < 2; i++) scanf("%lld", &vb[i][0]); build(); int q; cin >> q; for (int ii = 0; ii < q; ii++) { string s; cin >> s; if (s == "a") { int k; scanf("%d", &k); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) scanf("%lld", &seg[k + N].A[i][j]); } update(k); } else if (s == "b") { int k; scanf("%d", &k); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) scanf("%lld", &seg[k + N].B[i][j]); } update(k); } else if (s == "ga") { int k; scanf("%d", &k); auto ans = query(0, k).A * va; for (int i = 0; i < 3; i++) { printf("%lld ", ans[i][0]); } printf("\n"); } else if (s == "gb") { int k; scanf("%d", &k); auto X = query(k + 1, n + 1); auto Y = query(0, k + 1); auto ans = X.B * vb + X.S * Y.A * va; for (int i = 0; i < 2; i++) { printf("%lld ", ans[i][0]); } printf("\n"); } } }