import math class SegTree: def __init__(self, n, e, ope, lst=[]): self.N0 = 2 ** (n - 1).bit_length() self.e = e self.ope = ope self.data = [e] * (2 * self.N0) if lst: for i in range(n): self.data[self.N0 + i] = lst[i] for i in range(self.N0 - 1, 0, -1): self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1]) def build(self): for i in range(self.N0 - 1, 0, -1): self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1]) def update(self, i, x): #a_iの値をxに更新 i += self.N0 self.data[i] = x while i > 1: i >>= 1 self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1]) def add(self, i, x): self.update(i, x + self.get(i)) def set(self, i, x): self.data[self.N0 + i] = x def query(self, l, r): #区間[l, r)での演算結果 if r <= l: return self.e lres = self.e rres = self.e l += self.N0 r += self.N0 while l < r: if l & 1: lres = self.ope(lres, self.data[l]) l += 1 if r & 1: r -= 1 rres = self.ope(self.data[r], rres) l >>= 1 r >>= 1 return self.ope(lres, rres) def get(self, i): #a_iの値を返す return self.data[self.N0 + i] n = int(input()) A = [] for _ in range(n): p, q, r = map(float, input().split()) r = math.radians(r) z1 = p - p * math.cos(r) + q * math.sin(r) z2 = q - q * math.cos(r) - p * math.sin(r) alpha = math.cos(r) beta = math.sin(r) A.append((z1, z2, alpha, beta)) def ope(x, y): z1, z2, alpha, beta = x z1_, z2_, alpha_, beta_ = y zz1 = z1_ + alpha_ * z1 - beta_ * z2 aalpha = alpha_ * alpha - beta_ * beta bbeta = alpha_ * beta + beta_ * alpha zz2 = z2_ + alpha_ * z2 + beta_ * z1 return (zz1, zz2, aalpha, bbeta) e = (0, 0, 1, 0) seg = SegTree(n, e, ope, A) for _ in range(int(input())): s, t, x, y = map(float, input().split()) s = int(s) t = int(t) z1, z2, alpha, beta = seg.query(s - 1, t) x_ = z1 + alpha * x - beta * y y_ = z2 + alpha * y + beta * x print(x_, y_)