LaLa is about to cast a magical beast summoning magic.
The first thing LaLa do is creating a summoning field, which has 3 constants associated with it: nullity M, elasticity E, and viscosity V. Such summoning field is denoted by F(M,E,V)
A magical beast summoning magic is performed over a summoning cell within the summoning field, which is square-shaped and is associated with 3 variables: side length L, agility A, and intelligence I. Such summoning cell is denoted by C(L,A,I).
C(L,A,I) is in a null state if L=0. Otherwise, it is in a positive state.
The density of C(L,A,I) in positive state is defined as (A×I)/L2.
The problem of determining whether a magical beast summoning magic will succeed requires very heavy computation involving solving a system of 9999999999-th order partial differential equations over 9999999999999999 variables. Fortunately, LaLa already did all the math for you!
The magical beast summoning magic over C(L,A,I) within F(M,E,V) succeeds if and only if the function valid(M,E,V,L,A,I) defined by the pseudocode in the note section returns true. We'll call such summoning cell valid.
Sometimes, LaLa isn't satisfied with the set of summoning cells she has, and wants to generate new ones by combining them. The problem of determining the result of combination of two valid summoning cells C_0=C(L_0,A_0,I_0) and C_1=C(L_1,A_1,I_1) within F=F(M,E,V) requires another heavy computation, but thankfully, LaLa already did all the math for you again!
The result of combining two such cells C_0 and C_1 within F, denoted by Combine_F(C_0,C_1), is given by the function combine(M,E,V,L_0,A_0,I_0,L_1,A_1,I_1) defined by the pseudocode in the note section, which returns a triple L_2,A_2,I_2 satisfying C(L_2,A_2,I_2)=Combine_F(C_0,C_1). Here, it can be proved that Combine_F(C_0,C_1) is also valid. Note that swapping the order of C_0 and C_1 affects the result.
The result of combining K≥3 cells C_0,⋯,C_K−1 within F is given recursively by Combine_F(C_0,⋯,C_K−1)=Combine_F(Combine_F(C_0,⋯,C_K−2),C_K−1)
For the sake of completeness, we define Combine_F(C)=C.
LaLa is aware of a very special property about the combining operation that allows her to efficiently solve the range density query problem below. Can you figure it out?
You're given a summoning field F=F(M,E,V) and an array of N valid summoning cells C_0=C(L_0,A_0,I_0),⋯,C_N−1=C(L_N−1,A_N−1,I_N−1) within F. Write a program that processes the following two types of Q queries:
1 i L A I
2 l r
The input is given in the following format:
M E V
N
L_0 A_0 I_0
⋮
L_N−1 A_N−1 I_N−1
Q
q_0
⋮
q_Q−1
Here, q_i denotes the i-th query, and is given in the format described in the statement.
The input satisfies the following constraints:
1 i L A I, 0≤i<N, 0≤L,A,I<M, and C(L,A,I) is valid within F(M,E,V).2 l r, 0≤l<r≤NFor each query of the second type, print its answer in a single line.
The following pseudocode defines the validity of summoning cells and the Combine operation.
Both functions do not modify their arguments


The author has attached a C++ implementation which will get "Time Limit Exceeded" verdict upon submission, but it will always print the correct answer within finite time. You may reuse some part of the implementation on your submission. You can find it on the "Problemset" tab on the domjudge site.