Everybody loves Hypnotoad! Its show is one of the most popular on TV!
It is true that after the show nobody remembers what it was about and even what
they have been doing during all that time. However, this does not prevent
the numerous fans of Hypnotoad from enjoying their favorite show.
In order to study the amazing properties of Hypnotoad, Professor Farnsworth
constructed a special device, which trapped and scanned its waves. He found out
that at each time moment Hypnotoad's eyes could be in one of n states.
Professor denoted those states by the numbers 0, 1, …, n−1
for simplicity. The states of the eyes changed according to one of several
linear laws. There were m such laws and each of them could be specified by
five integers:
s_{0}, t_{0}, Δs, Δt, k.
When Hypnotoad “worked” according to such a law, its left eye switched to
the state s_{i} and its right eye switched to
the state t_{i} successively
for all integers i from 0 to k−1, where
s_{i} = (s_{0} + i Δs) mod n,
t_{i} = (t_{0} + i Δt) mod n.
After several weeks of research, Farnsworth understood that Hypnotoad's waves
could be used to learn many secrets of the Universe. For example, Hypnotoad could
see the dark matter and extract information from black holes. In order to see
the same way Hypnotoad saw, Professor constructed another device that emulated
“hypnosight”: each of its four oculars could stay in one of the n
states changing according to linear laws. Farnsworth carried out a series of
experiments and decided to draw a diagram in which he would mark for every possible state
of the device whether Hypnotoad's eyes could be in states similar to the states of
the oculars. Help Professor automate this process.
One experiment is described by nine integers:
a_{0}, b_{0}, c_{0}, d_{0},
Δa, Δb, Δc, Δd, q.
For all integer values of j from 0 to q−1, the oculars successively switch to
the following states:
a_{j} = (a_{0} + j Δa) mod n,
b_{j} = (b_{0} + j Δb) mod n,
c_{j} = (c_{0} + j Δc) mod n,
d_{j} = (d_{0} + j Δd) mod n.
For every state of the device (a_{j}, b_{j},
c_{j}, d_{j}), it is required to determine
whether Hypnotoad's eyes can be in a state
(s_{i}, t_{i}) such that
min(a_{j}, b_{j}) ≤
s_{i} ≤
max(a_{j}, b_{j}),
min(c_{j}, d_{j}) ≤
t_{i} ≤
max(c_{j}, d_{j}).
Input
In the first line you are given the number n of states of Hypnotoad's eyes
and the number m of laws of their behavior
(1 ≤ n ≤ 5000, 1 ≤ m ≤ 1000).
Each of the following m lines contains the integers
s_{0}, t_{0}, Δs, Δt, k,
which specify the law according to which the states of the eyes are switched
(0 ≤ s_{0}, t_{0}, Δs,
Δt ≤ n−1; 1 ≤ k ≤ 567).
In the next line you are given the number p of experiments
(1 ≤ p ≤ 345). Each of the following p lines contains the integers
a_{0}, b_{0}, c_{0}, d_{0},
Δa, Δb, Δc, Δd, q,
which describe the experiment
(0 ≤ a_{0}, b_{0}, c_{0},
d_{0}, Δa, Δb, Δc,
Δd ≤ n−1; 1 ≤ q ≤ 345).
Output
Output p lines, one line per experiment. For each experiment, determine
its result: the set of numbers x_{j} for j = 0, 1, …, q−1.
In this set, x_{j} = 1 if Hypnotoad's eyes can be in a state complying
with the corresponding state of the device and x_{j} = 0 otherwise.
If q ≤ 20, output all x_{j} in a row without spaces.
If q > 20, output one number equal to
Sample
input  output 

3 3
0 1 0 0 1
1 2 0 0 1
2 0 0 0 1
5
0 0 1 1 0 0 0 0 5
1 1 0 0 0 0 0 0 3
0 1 0 0 0 0 0 0 345
1 2 1 1 0 0 0 1 4
1 2 1 1 0 0 0 1 3
 11111
000
0
0110
011

Problem Author: Dmitry Ivankov
Problem Source: The 13th Urals Collegiate Programing Championship, April 04, 2009