import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
double[] k = new double[n + 1];
for(int i = 0 ; i <= n ; i++){
k[i] = 1;
}
double[] sita = new double[n + 1];
for(int i = 1 ; i <= n ; i++){
int type = scan.nextInt();
double val = scan.nextDouble();
if(type == 1){
k[i] = k[i - 1] * val;
sita[i] = sita[i - 1];
}else{
k[i] = k[i - 1];
sita[i] = sita[i - 1] + val;
}
}
for(int i = 0 ; i < m ; i++){
int l = scan.nextInt();
int r = scan.nextInt();
double x = scan.nextDouble();
double y = scan.nextDouble();
double sum_sita = sita[r] - sita[l - 1];
double sum_k = k[r] / k[l - 1];
double nx = x * Math.cos(sum_sita) - y * Math.sin(sum_sita);
double ny = x * Math.sin(sum_sita) + y * Math.cos(sum_sita);
System.out.println(nx * sum_k + " " + ny * sum_k);
}
}
}