from math import sin,cos,atan2,sqrt,radians,pi class Segment_Tree(): """ このプログラム内は1-index """ def __init__(self,L,calc,unit): """calcを演算とするリストLのSegment Treeを作成 calc:演算(2変数関数,モノイド) unit:モノイドcalcの単位元 (xe=ex=xを満たすe) """ self.calc=calc self.unit=unit N=len(L) d=max(1,(N-1).bit_length()) k=1<1: m>>=1 self.data[m]=self.calc(self.data[m<<1],self.data[m<<1|1]) def product(self,From,To,index=1,left_closed=True,right_closed=True): L=(From-index)+self.N+(not left_closed) R=(To-index)+self.N+(right_closed) vL=self.unit vR=self.unit while L>=1 R>>=1 return self.calc(vL,vR) def all_prod(self): return self.data[1] def calc(X,Y): r1,t1,f1=X r2,t2,f2=Y p=r1*cos(t1)+r2*cos(t2+f1) q=r1*sin(t1)+r2*sin(t2+f1) return (sqrt(p*p+q*q),atan2(q,p),f1+f2) #================================================= N,Q=map(int,input().split()) A=[(1,0,0) for _ in range(N)] S=Segment_Tree(A,calc,(0,0,0)) X=[] for _ in range(Q): T=tuple(map(int,input().split())) if T[0]==0: _,i,theta=T r,t,f=S.get(i,1) S.update(i,(r,radians(theta),radians(theta)),1) elif T[0]==1: _,i,x=T r,t,f=S.get(i,1) S.update(i,(x,t,f),1) else: _,x=T r,t,f=S.product(1,x,1) X.append("{} {}".format(r*cos(t),r*sin(t))) print("\n".join(map(str,X)))