import java.util.*;
class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
double[] s = new double[n + 10];
s[0] = 1;
double[] con = new double[n + 10];
for (int i = 1; i <= n; i ++) {
int a = in.nextInt();
double b = in.nextDouble();
if (a == 1) {
s[i] = s[i - 1] * b;
con[i] = con[i - 1];
} else {
s[i] = s[i - 1];
con[i] = con[i - 1] + b;
}
}
for (int i = 0; i < m; i ++) {
int a = in.nextInt();
int b = in.nextInt();
double x = in.nextDouble();
double y = in.nextDouble();
double c = x;
x = x * Math.cos(con[b] - con[a - 1]) - y * Math.sin(con[b] - con[a - 1]);
y = c * Math.sin(con[b] - con[a - 1]) + y * Math.cos(con[b] - con[a - 1]);
x = x * (s[b] / s[a - 1]);
y = y * (s[b] / s[a - 1]);
System.out.println(x + " " + y);
}
}
}
acwing能过,官网却显示部分数据超时,只能过80,有没有老铁和我一样的情况