#include "bits/stdc++.h" using namespace std; #define rep(i,n) for(int i=0;itrans(matrix m, double x, double y) { vectorres(2); res[0] = m.dat[0][0] * x + m.dat[0][1] * y + m.dat[0][2]; res[1] = m.dat[1][0] * x + m.dat[1][1] * y + m.dat[1][2]; return res; } struct segtree { matrix ide; vectornode; int n; void init(int N) { n = 1; while (n < N)n *= 2; node.resize(2 * n); } void upd(double theta, double p, double q, int k) { k += n - 1; node[k].init(theta, p, q); while (k > 0) { k = (k - 1) / 2; node[k] = mul(node[k * 2 + 1], node[k * 2 + 2]); } } matrix calc(int a, int b, int k, int l, int r) { if (r <= a || b <= l)return ide; if (a <= l&&r <= b)return node[k]; matrix vl = calc(a, b, k * 2 + 1, l, (l + r) / 2); matrix vr = calc(a, b, k * 2 + 2, (l + r) / 2, r); return mul(vl,vr); } matrix get(int a, int b) { return calc(a, b, 0, 0, n); } }; segtree seg; signed main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; seg.init(n); if (n > 100000)MRE; rep(i, n) { double p, q, r; cin >> p >> q >> r; if (abs(p) > 1000 || abs(q) > 1000)MRE; if (abs(r) > 360)MRE; seg.upd(r, p, q, i); P[i] = p; Q[i] = q; R[i] = r; } int q; cin >> q; if (q > 100000)MRE; rep(j, q) { int s, t; double x, y; cin >> s >> t >> x >> y; if (s > n || t > n)MRE; if (s < 1 || t < 1)MRE; if (abs(x) > 1000 || abs(y) > 1000)MRE; vectorres(2); res={ x,y }; for (int i = s - 1; i < t; i++) { matrix M; M.init(R[i], P[i], Q[i]); res = trans(M, res[0], res[1]); } printf("%.13Lf %.13Lf\n", res[0], res[1]); } }