#include using namespace std; typedef long long int64; const int mod = 1e9 + 7; int N, Q; int64 A[100000][3][3]; int64 B[100000][2][2]; int64 a[100000][3]; int64 b[100000][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 + 2][1] %= mod; a[i + 3][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 >> 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]; } for(int i = 0; i < N; i++) nextA(i); for(int i = N; i > 0; i--) prevB(i); } 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]; } for(int i = N; i > 0; i--) prevB(i); } else if(type == "ga") { int idx; cin >> idx; cout << a[idx][0] << " " << a[idx][1] << " " << a[idx][2] << endl; } else { int idx; cin >> idx; cout << b[idx][0] << " " << b[idx][1] << endl; } } }