#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } double deg2rad(double deg){ return deg*M_PI/180.0; } template class Matrix { public: array, N> dat; Matrix(T val) { for(int i = 0; i < N; i++){ for(int j = 0; j < M; j++){ dat[i][j] = val; } } } Matrix(array, N> dat): dat(dat){ } array& operator[](int x) { return dat[x]; } }; template Matrix operator*(Matrix a, Matrix b){ Matrix c(T(0)); for(int i = 0; i < N; i++){ for(int j = 0; j < K; j++){ for(int k = 0; k < M; k++){ c.dat[i][j] += a.dat[i][k]*b.dat[k][j]; } } } return c; } template void print_mat(Matrix a){ for(int i = 0; i < N; i++){ for(int j = 0; j < M; j++){ cout << a.dat[i][j] << ' '; } cout << endl; } } template ostream& operator<<(ostream& os, const Matrix& m){ print_mat(m); return os; } using M = Matrix; using V = Matrix; M e_(){ M ans(0.0); for(int i = 0; i < 3; i++) ans[i][i] = 1.0; return ans; } M I = e_(); M e(){ return I; } M rot(double t){ M ans(0.0); ans[2][2] = 1; ans[0][0] = cos(t); ans[0][1] = -sin(t); ans[1][0] = sin(t); ans[1][1] = cos(t); return ans; } M move_mat(double p, double q){ M ans(0.0); ans[0][0] = 1; ans[1][1] = 1; ans[2][2] = 1; ans[0][2] = p; ans[1][2] = q; return ans; } M op(M a, M b){ return a*b; } M calc(double t, double p, double q){ return move_mat(p, q)*rot(t)*move_mat(-p, -q); } using Seg = atcoder::segtree; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector p(n), q(n), r(n); Seg seg(n); for(int i = 0; i < n; i++){ cin >> p[i] >> q[i] >> r[i]; r[i] = deg2rad(r[i]); // cout << calc(r[i], p[i], q[i]) << endl; seg.set(n-i-1, calc(r[i], p[i], q[i])); } int Q; cin >> Q; while(Q--){ int s, t; cin >> s >> t; s--; t--; double x, y; cin >> x >> y; s = n-1-s; t = n-1-t; swap(s, t); M m = seg.prod(s, t+1); // cout << s << ' ' << t << endl; V v(0.0); v[0][0] = x; v[1][0] = y; v[2][0] = 1; V u = m*v; // cout << m << endl; // cout << u << endl; cout << u[0][0] << ' ' << u[1][0] << endl; } }