import math from decimal import Decimal class SegTree: """ init(init_val, ide_ele): 配列init_valで初期化 O(N) update(k, x): k番目の値をxに更新 O(logN) query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN) """ def __init__(self, init_val, segfunc, ide_ele): """ init_val: 配列の初期値 segfunc: 区間にしたい操作 ide_ele: 単位元 n: 要素数 num: n以上の最小の2のべき乗 tree: セグメント木(1-index) """ n = len(init_val) self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1 << (n - 1).bit_length() self.tree = [ide_ele] * 2 * self.num # 配列の値を葉にセット for i in range(n): self.tree[self.num + i] = init_val[i] # 構築していく for i in range(self.num - 1, 0, -1): self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1]) def update(self, k, x): """ k番目の値をxに更新 k: index(0-index) x: update value """ k += self.num self.tree[k] = x while k > 1: self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1]) k >>= 1 def query(self, l, r): """ [l, r)のsegfuncしたものを得る l: index(0-index) r: index(0-index) """ res = self.ide_ele l += self.num r += self.num while l < r: if l & 1: res = self.segfunc(res, self.tree[l]) l += 1 if r & 1: res = self.segfunc(res, self.tree[r - 1]) l >>= 1 r >>= 1 return res def value(self,index): return self.query(index,index+1) def conv(p,q,r): rad = math.radians(r) COS = Decimal(math.cos(rad)) SIN = Decimal(math.sin(rad)) rev = [[COS,-SIN, -p * COS + q * SIN + p], [SIN,COS,- p * SIN -q * COS + q], [0,0,1] ] return rev def multply(A,B): C = [[0] * len(B[0]) for _ in range(len(A))] for i in range(len(A)): for k in range(len(B[0])): for m in range(len(B)): C[i][k] += A[i][m] * B[m][k] return C def remultply(A,B): C = [[0] * len(A[0]) for _ in range(len(B))] for i in range(len(B)): for k in range(len(A[0])): for m in range(len(A)): C[i][k] += B[i][m] * A[m][k] return C board = [] N = int(input()) for _ in range(N): p,q,r = map(Decimal,input().split()) mat = conv(p,q,r) board.append(mat) e = [[1,0,0],[0,1,0],[0,0,1]] seg = SegTree(board,remultply,e) Q = int(input()) ANS = [] for _ in range(Q): s,t,x,y = map(Decimal,input().split()) s = int(s) t = int(t) s-=1 t-=1 ans = multply(seg.query(s,t+1),[[x],[y],[1]]) ANS.append((ans[0][0],ans[1][0])) for x,y in ANS: print(float(x),float(y))