def conv(p,q): pa,pb=p qa,qb=q return (pa*qa, pb+pa*qb) def inv(p): pa,pb=p return (1/pa,-pb/pa) from math import * N=int(input()) d=[None]*(N+1); d[0]=(1,0) for i in range(N): p,q,r=map(float,input().split()) alpha=complex(p,q) theta=r/180*pi beta=complex(cos(theta), sin(theta)) d[i+1]=(beta, alpha*(1-beta)) for i in range(1,N+1): d[i]=conv(d[i], d[i-1]) Q=int(input()) for q in range(Q): s,t,x,y=input().split() s=int(s); t=int(t) x=float(x); y=float(y) p=conv(d[t],inv(d[s-1])) zeta=complex(x,y) eta=p[0]*zeta+p[1] print(eta.real,eta.imag)