... Why don't you come to the planetarium?
The beautiful twinkling of eternity that will never fade, no matter what.
All the stars in the sky are waiting for you...
A planetarium, it was once where people went to soothe their hearts by gazing at a starry sky.
And Yumemi, a planetarium guide who has been waiting for a visitor for a long time, is looking up at the stars.
The sky can be regarded as a 2-D Cartesian coordinate system. There are stars in the sky, and the position of the
-th star is
initially.
But the night sky is not always the same. The positions of some stars may change. So you need to help Yumemi handle queries. The
-th query is one of the following two:
Stars numbered within rotate
counter clockwise around
.
Given and
, ask for the value of
, where
indicates the current position of the
-th star.
The first line contains two integers
and
(
).
The-th of the next
lines contains two integers
.
The-th of the next
lines contains five integers
or three integers
, which respectively represent two different queries.
Output the answer to the corresponding queryin each line. Note that you need to output the value modulo
.