This problem might be well-known in some countries, but how do other countries learn about such problems if nobody poses them.
There are n points on the plane, where the i-th point (x_i,y_i) has value d_i∈D. Two sets D and O are given, with the following properties:
There exists a special element ε_D in D.
There exists a special element ε_O in O.
A binary operation +:D×D→D is given with the following properties:
A binary operation ⋅:O×D→D is given with the following properties:
A binary operation ⋅:O×O→O is given with the following properties:
In this problem, we treat D as the set of all 3×1 matrices over F_p and O as the set of all 3×3 matrices over F_p, where p=109+7. That is, you can treat the above operations as the usual matrix addition and matrix multiplication modulo 109+7.
Now, m queries are given in the form a b c o:
As a data structure master, you need to perform all queries and find the answer.
The first line of the input contains a single integer n (1≤n≤3⋅105), indicating the number of points.
Each of the following n lines contains five integers x_i,y_i,d_i0,d_i1,d_i2, indicating the coordinates of the i-th point and its value \mathbf d\_i = \left\[\begin{matrix}d\_{i0}\\\d\_{i1}\\\d\_{i2}\end{matrix}\right].
The next line of the input contains a single integer m (1≤m≤1.5⋅104), indicating the number of the queries.
Each of the following m lines contains twelve integers a,b,c,o_00,o_01,o_02,o_10,…,o_22. Note that the real \mathbf o = \left\[\begin{matrix} o\_{00} & o\_{01} & o\_{02} \\\ o\_{10} & o\_{11} & o\_{12}\\\ o\_{20} & o\_{21} & o\_{22}\end{matrix}\right].
It is guaranteed that:
For each query, output a single line containing three integers s_0,s_1,s_2, indicating \mathbf s = \left\[\begin{matrix}s\_{0}\\\s\_{1}\\\s\_{2}\end{matrix}\right].
Note that the solution does not depend on other properties of matrix addition/multiplication than those mentioned in the statements. Defining D and O as sets of matrices is only for testing convenience (since we can't use the graders or interaction libraries).