import math import numpy as np n = int(input()) s = [] s.append(np.identity(3, dtype=np.float64)) for _ in range(n): pi, qi, ri = map(float, input().split()) theta = (2 * math.pi * ri) / 360 ct = math.cos(theta) st = math.sin(theta) s.append(np.array([[ct, - st, - pi * ct + qi * st + pi], [st, ct, - pi * st - qi * ct + qi], [0, 0, 1.0]]) @ s[-1]) q = int(input()) for _ in range(q): sj, tj, xj, yj = input().split() m = s[int(tj)] @ np.linalg.inv(s[int(sj) - 1]) v = m @ np.array([float(xj), float(yj), 1.0]) print(f"{v[0]:.6f} {v[1]:.6f}")