#include<bits/stdc++.h>usingnamespace std;intmain(){int n, m;
cin >> n >> m;//用vector来使用动态数组
vector<double>a(n+1);
vector<double>b(n+1);for(int i =1; i <= n; i++){int x;
cin >> x;if(x ==1){
cin >> a[i];
b[i]=0;}else{
cin >> b[i];
a[i]=1;}}
vector<double>sum1(n+2),sum2(n+2);
sum1[0]=1;
sum2[0]=0;//直接计算前缀和(根据递推关系式直接求解)for(int i =1; i <=n; i++){
sum1[i]= a[i]* sum1[i -1];
sum2[i]= b[i]+ sum2[i -1];}//根据所给公式计算m次的结果for(int i =0; i < m; i++){int start, end;double x, y;
cin >> start >> end >> x >> y;double k = sum1[end]/ sum1[start -1];double theta = sum2[end]- sum2[start -1];
x = x * k;
y = y * k;double temp = x;
x = x *cos(theta)- y *sin(theta);
y = temp *sin(theta)+ y *cos(theta);printf("%.3lf %.3lf\n", x, y);}return0;}