#include #include using namespace std; using namespace atcoder; typedef int64_t lint; #define rep(i, n) for(int i=0; i; using vvi = vector>; template inline void vin(vector& v) { rep(i, v.size()) cin >> v.at(i); } 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; } template inline void drop(T x) { cout << x << endl; exit(0); } template void vout(vector v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; } constexpr lint LINF = LLONG_MAX/2; constexpr double PI=3.14159265358979323846; #define deg_to_rad(deg) (((deg)/360)*2*PI) #define rad_to_deg(rad) (((rad)/2/PI)*360) vvi matrix_mul(vvi A, vvi B) { vvi C(A.size(), vi(B[0].size())); rep(i, A.size()) { rep(k, B.size()) { rep(j, B[0].size()) { C[i][j] += A[i][k] * B[k][j]; } } } return C; } int main() { lint N, Q; cin >> N; vi p(N), q(N), r(N); rep(i, N) cin >> p[i] >> q[i] >> r[i]; lint a=0, b=0, c=0; double x, y, z; std::vector v, w; vvi e(3, vi(3)); e[0][0] = 1; e[1][1] = 1; e[2][2] = 1; v.pb(e); w.pb(e); rep(i, N) { vvi t(3, vi(3)); x = sin(deg_to_rad(r[i])); y = cos(deg_to_rad(r[i])); t[0][0] = y; t[0][1] = -x; t[0][2] = p[i]-p[i]*y+q[i]*x; t[1][0] = x; t[1][1] = y; t[1][2] = q[i]-p[i]*x-q[i]*y; t[2][2] = 1; v.pb(t); x = sin(deg_to_rad(-r[i])); y = cos(deg_to_rad(-r[i])); t[0][0] = y; t[0][1] = -x; t[0][2] = p[i]-p[i]*y+q[i]*x; t[1][0] = x; t[1][1] = y; t[1][2] = q[i]-p[i]*x-q[i]*y; t[2][2] = 1; w.pb(t); } // cout << fixed << setprecision(10); // rep(i, N) { // rep(j, 3) { // rep(k, 3) { // std::cout << v[i][j][k] << ' '; // } // std::cout << '\n'; // } // std::cout << '\n'; // } rep(i, N) { v[i+1] = matrix_mul(v[i+1], v[i]); w[i+1] = matrix_mul(w[i], w[i+1]); } cin >> Q; rep(_, Q) { cin >> a >> b >> x >> y; a--; vvi t(3, vi(1)); t[0][0] = x; t[1][0] = y; t[2][0] = 1; // t = matrix_mul(w[a], t); // cout << fixed << setprecision(10) << t[0][0] << ' ' << t[1][0] << endl; // t = matrix_mul(v[b], t); // cout << fixed << setprecision(10) << t[0][0] << ' ' << t[1][0] << endl; // std::cout << '\n'; t = matrix_mul(matrix_mul(v[b], w[a]), t); cout << fixed << setprecision(10) << t[0][0] << ' ' << t[1][0] << endl; } // rep(i, N) { // rep(j, 3) { // rep(k, 3) { // std::cout << v[i][j][k] << ' '; // } // std::cout << '\n'; // } // std::cout << '\n'; // } }