#include using namespace std; typedef long long int64; const int mod = 1e9 + 7; int N, Q; int64 A[100001][3][3]; int64 B[100001][2][2]; int64 a[100001][3]; int64 b[100001][2]; bool updatable[2]; void nextA(int i) { a[i + 1][0] = A[i][0][0] * a[i][0] + A[i][0][1] * a[i][1] + A[i][0][2] * a[i][2]; a[i + 1][1] = A[i][1][0] * a[i][0] + A[i][1][1] * a[i][1] + A[i][1][2] * a[i][2]; a[i + 1][2] = A[i][2][0] * a[i][0] + A[i][2][1] * a[i][1] + A[i][2][2] * a[i][2]; a[i + 1][0] %= mod; a[i + 1][1] %= mod; a[i + 1][2] %= mod; } void prevB(int i) { b[i - 1][0] = B[i][0][0] * b[i][0] + B[i][0][1] * b[i][1]; b[i - 1][1] = B[i][1][0] * b[i][0] + B[i][1][1] * b[i][1]; b[i - 1][0] += (6 * i + 0) * a[i][0] + (6 * i + 1) * a[i][1] + (6 * i + 2) * a[i][2]; b[i - 1][1] += (6 * i + 3) * a[i][0] + (6 * i + 4) * a[i][1] + (6 * i + 5) * a[i][2]; b[i - 1][0] %= mod; b[i - 1][1] %= mod; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; for(int i = 0; i < 3; i++) cin >> a[0][i]; for(int i = 0; i < 2; i++) cin >> b[N][i]; for(int i = 0; i <= N; i++) for(int j = 0; j < 3; j++) A[i][j][j] = 1; for(int i = 0; i <= N; i++) for(int j = 0; j < 2; j++) B[i][j][j] = 1; for(int i = 0; i < N; i++) nextA(i); for(int i = N; i > 0; i--) prevB(i); cin >> Q; while(Q--) { string type; cin >> type; if(type == "a") { int idx; cin >> idx; for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) cin >> A[idx][i][j]; } updatable[0] = true; } else if(type == "b") { int idx; cin >> idx; for(int i = 0; i < 2; i++) { for(int j = 0; j < 2; j++) cin >> B[idx][i][j]; } updatable[1] = true; } else if(type == "ga") { if(updatable[0]) { for(int i = 0; i < N; i++) nextA(i); updatable[1] = true; } updatable[0] = false; int idx; cin >> idx; cout << a[idx][0] << " " << a[idx][1] << " " << a[idx][2] << endl; } else { if(updatable[0] | updatable[1]) { if(updatable[0]) for(int i = 0; i < N; i++) nextA(i); for(int i = N; i > 0; i--) prevB(i); } updatable[0] = updatable[1] = false; int idx; cin >> idx; cout << b[idx][0] << " " << b[idx][1] << endl; } } }