#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000000 template struct matrix{ vector> v; int _h,_w; matrix(){ } matrix(vector> X){ v = X; _h = X.size(); _w = 0; if(X.size()>0)_w = X[0].size(); } matrix(int h,int w){ v.resize(h,vector(w,e0())); _h = h; _w = w; } void add_element(int from,int to,S x){ v[to][from] = op0(v[to][from],x); } matrix e(){ assert(_h==_w); matrix ret(_h,_w); for(int i=0;i<_h;i++){ for(int j=0;j<_w;j++){ if(i==j)ret.v[i][j] = e1(); else ret.v[i][j] = e0(); } } return ret; } matrix &operator*=(const matrix &another){ matrix ret(_h,another._w); for(int i=0;i<_h;i++){ for(int j=0;j ret = e(); auto temp = *this; while(cnt!=0LL){ if((cnt&1)==1){ ret *= temp; } temp *= temp; cnt>>=1; } return ret; } }; double op0(double a,double b){ return a+b; } double e0(){ return 0.0; } double op1(double a,double b){ return a*b; } double e1(){ return 1.0; } using M = matrix; M op(M a,M b){ return b*a; } M e(){ M ret(3,3); return ret.e(); } int main(){ int N,Q; cin>>N; vector temp(N); rep(i,N){ auto t = e(); double p,q,r; cin>>p>>q>>r; t.add_element(2,0,-p); t.add_element(2,1,-q); { M tt(3,3); tt.add_element(2,2,1); r /= 360.0; r *= acos(-1.0) * 2.0; tt.add_element(0,0,cos(r)); tt.add_element(1,0,-sin(r)); tt.add_element(0,1,sin(r)); tt.add_element(1,1,cos(r)); t = tt* t; } { auto tt = e(); tt.add_element(2,0,p); tt.add_element(2,1,q); t = tt*t; } temp[i] = t; } segtree seg(temp); cin>>Q; rep(_,Q){ int s,t; cin>>s>>t; double x,y; cin>>x>>y; M tt(3,1); tt.v[0][0] = x; tt.v[1][0]=y; tt.v[2][0]=1.0; tt = seg.prod(s-1,t) * tt; cout<