#include #include #include using namespace std; //----------------------- int MOD; struct mint { int n; mint(int n_ = 0) : n(n_ % MOD) { if (n < 0) n += MOD; } }; mint operator+(mint a, mint b) { return (a.n += b.n) >= MOD ? a.n - MOD : a.n; } mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + MOD : a.n; } mint operator*(mint a, mint b) { return 1LL * a.n * b.n % MOD; } mint &operator+=(mint &a, mint b) { return a = a + b; } mint &operator-=(mint &a, mint b) { return a = a - b; } mint &operator*=(mint &a, mint b) { return a = a * b; } ostream &operator<<(ostream &os, mint a) { return os << a.n; } istream &operator>>(istream &is, mint& a) { return is >> a.n; } mint inv(mint x) { long long a = x.n, b = MOD, u = 1, v = 0; while (b) { long long t = a/b; swap((a -= t*b), b); swap((u -= t*v), v); } return mint(u); } mint operator^(mint a, long long n) { mint r = 1; while (n) { if (n & 1) r *= a; a *= a; n >>= 1; } return r; } bool operator<(const mint &a, const mint &b) { return a.n < b.n; } //----------------------- template ostream& operator<<(ostream& os, const vector& vec) { for (auto &vi: vec) os << vi << " "; return os; } template struct Matrix { vector> val; Matrix(int n = 1, int m = 1, T x = 0) { val.assign(n, vector(m, x)); } size_t size() const { return val.size(); } vector& operator[](int i) { return val[i]; } const vector& operator[](int i) const { return val[i]; } friend ostream& operator<<(ostream& os, const Matrix M) { for (int i = 0; i < M.size(); ++i) os << M[i] << " \n"[i != M.size() - 1]; return os; } }; template Matrix operator^(Matrix A, long long n) { Matrix R(A.size(), A.size()); for (int i = 0; i < A.size(); ++i) R[i][i] = 1; while (n > 0) { if (n & 1) R = R * A; A = A * A; n >>= 1; } return R; } template Matrix operator*(const Matrix& A, const Matrix& B) { Matrix R(A.size(), B[0].size()); for (int i = 0; i < A.size(); ++i) for (int j = 0; j < B[0].size(); ++j) for (int k = 0; k < B.size(); ++k) R[i][j] += A[i][k] * B[k][j]; return R; } template vector operator*(const Matrix &A, vector &B) { vector v(A.size()); for (int i = 0; i < A.size(); ++i) for (int k = 0; k < B.size(); ++k) v[i] += A[i][k] * B[k]; return v; } template T affine2(T a, T b, long long n, T x1 = 1) { Matrix A(2, 2); A[0][0] = a; A[0][1] = b; // x[k + 1] = a * x[k] + b A[1][0] = 0; A[1][1] = 1; auto pow = A ^ (n - 1); return pow[0][0] * x1 + pow[0][1]; } template Matrix affine2D(T p = T(1), T q = T(0), T r = T(0), T s = T(1), T b1 = T(0), T b2 = T(0)) { Matrix A(3, 3); A[0][0] = p; A[0][1] = q; A[0][2] = b1; // ⎛y1⎞ ⎛p q⎞ ⎛x1⎞ ⎛b1⎞ A[1][0] = r; A[1][1] = s; A[1][2] = b2; // ⎝y2⎠ = ⎝r s⎠ ⎝x2⎠ * ⎝b2⎠ A[2][0] = 0; A[2][1] = 0; A[2][2] = 1; return A; } template Matrix rot(T theta) { return affine2D(cos(theta), -sin(theta), sin(theta), cos(theta), 0, 0); } template Matrix rot_cw90() { return affine2D(T(0), T(1), -T(1), T(0), T(0), T(0)); } template Matrix rot_ccw90() { return affine2D(T(0), -T(1), T(1), T(0), T(0), T(0)); } template Matrix trans(T b1, T b2) { return affine2D(T(1), T(0), T(0), T(1), b1, b2); } int main() { int n; cin >> n; vector p(3, 1); cin >> p[0] >> p[1]; vector> a(n); for (int i = n - 1; i >= 0; i--) { int com; cin >> com; if (com == 1) { long long dx; cin >> dx; a[i] = trans(dx, 0); } if (com == 2) { long long dy; cin >> dy; a[i] = trans(0, dy); } if (com == 3) a[i] = rot_cw90(); } vector> acc(n + 1); acc[0] = Matrix(3, 3) ^ 0; for (int i = 0; i < n; i++) acc[i + 1] = acc[i] * a[i]; for (int i = n; i > 0; i--) { auto res = acc[i] * p; cout << res[0] << " " << res[1] << endl; } return 0; }