using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static double[] NList => ReadLine().Split().Select(double.Parse).ToArray(); static double[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var map = NArr(n); var q = NN; var query = NArr(q); var inlist = new List<(int i, int s, double x, double y)>(); var outlist = new List<(int i, int t, double x, double y)>(); for (var i = 0; i < q; ++i) { inlist.Add((i, (int)query[i][0] - 1, query[i][2], query[i][3])); outlist.Add((i, (int)query[i][1] - 1, query[i][2], query[i][3])); } inlist.Sort((l, r) => l.s.CompareTo(r.s)); outlist.Sort((l, r) => l.t.CompareTo(r.t)); var zero = new double[2]; var vec = new double[] { 1, 0 }; var pts = new double[q][]; var ipos = 0; var opos = 0; var ans = new double[q][]; for (var i = 0; i < n; ++i) { while (ipos < inlist.Count && inlist[ipos].s == i) { pts[inlist[ipos].i] = ToAbs(zero, vec, inlist[ipos].x, inlist[ipos].y); ++ipos; } var center = ToAbs(zero, vec, map[i][0], map[i][1]); zero = Rotate(new double[] { zero[0] - center[0], zero[1] - center[1] }, - map[i][2]); zero[0] += center[0]; zero[1] += center[1]; vec = Rotate(vec, - map[i][2]); while (opos < outlist.Count && outlist[opos].t == i) { ans[outlist[opos].i] = ToRel(zero, vec, pts[outlist[opos].i]); ++opos; } } WriteLine(string.Join("\n", ans.Select(ai => string.Join(" ", ai)))); } static double[] ToAbs(double[] zero, double[] vec, double x, double y) { return new double[] { zero[0] + vec[0] * x - vec[1] * y, zero[1] + vec[1] * x + vec[0] * y }; } static double[] ToRel(double[] zero, double[] vec, double[] a) { var rx = a[0] - zero[0]; var ry = a[1] - zero[1]; return new double[] { rx * vec[0] + ry * vec[1], - rx * vec[1] + ry * vec[0] }; } static double[] Rotate(double[] a, double r) { var sin = Math.Sin(r * Math.PI / 180); var cos = Math.Cos(r * Math.PI / 180); return new double[] { a[0] * cos - a[1] * sin, a[0] * sin + a[1] * cos }; } }