from cmath import pi, rect import sys input = sys.stdin.readline class SegmentTree: def __init__(self, size, op, identity): n = 1 << (size - 1).bit_length() self.size = n self.op = op self.identity = identity self.node = [identity] * (2 * n) def __getitem__(self, k): return self.node[k + self.size] def build(self, v): for k in range(len(v)): self.node[k + self.size] = v[k] for k in range(self.size - 1, 0, -1): self.node[k] = self.op(self.node[2 * k], self.node[2 * k + 1]) def update(self, k, x): k += self.size self.node[k] = x while k > 1: k >>= 1 self.node[k] = self.op(self.node[2 * k], self.node[2 * k + 1]) def fold(self, l, r): vl = vr = self.identity l += self.size r += self.size while l < r: if l & 1: vl = self.op(vl, self.node[l]) l += 1 if r & 1: r -= 1 vr = self.op(self.node[r], vr) l >>= 1 r >>= 1 return self.op(vl, vr) N = int(input()) mat = [None] * N for i in range(N): p, q, r = map(float, input().split()) z = p+q*1j c = rect(1, r/180*pi) mat[i] = [[c, -z*(c-1)], [0, 1]] matmul = lambda A, B: [[sum(B[i][k]*A[k][j] for k in range(2)) for j in range(2)] for i in range(2)] st = SegmentTree(N, matmul, [[1, 0], [0, 1]]) st.build(mat) Q = int(input()) for _ in range(Q): s, t, x, y = map(float, input().split()) s, t = int(s), int(t) p = x+y*1j A = st.fold(s-1, t) ans = A[0][0]*p + A[0][1] print(ans.real, ans.imag)