Quaternion inverse

No attempts yetTime limit1sMemory limit256 MB

Problem

A quaternion extends the complex numbers. It is written with three imaginary units ii, jj, kk that satisfy i2=j2=k2=ijk=1i^2 = j^2 = k^2 = ijk = -1, so it has four real components. This problem deals only with the quaternions in the set below, called restricted quaternions.

a+bi+cj+dk(a,b,c,d are integers with 0a,b,c,d<M)a + bi + cj + dk \qquad (a, b, c, d \text{ are integers with } 0 \le a, b, c, d < M)

Because of the relations among ii, jj, kk, the product of two ordinary quaternions is the following.

(a1+b1i+c1j+d1k)(a2+b2i+c2j+d2k)=(a1a2b1b2c1c2d1d2)+(a1b2+b1a2+c1d2d1c2)i+(a1c2b1d2+c1a2+d1b2)j+(a1d2+b1c2c1b2+d1a2)k\begin{aligned} &(a_1 + b_1i + c_1j + d_1k)(a_2 + b_2i + c_2j + d_2k) \\ &= (a_1a_2 - b_1b_2 - c_1c_2 - d_1d_2) \\ &+ (a_1b_2 + b_1a_2 + c_1d_2 - d_1c_2)i \\ &+ (a_1c_2 - b_1d_2 + c_1a_2 + d_1b_2)j \\ &+ (a_1d_2 + b_1c_2 - c_1b_2 + d_1a_2)k \end{aligned}

The product of two restricted quaternions is defined as the product of the same two quaternions taken as ordinary quaternions, with every integer component replaced by its remainder modulo MM.

Given MM and a restricted quaternion AA, find the restricted quaternion BB with AB=1AB = 1.

Input

The first line has two natural numbers MM and TT (1T1000001 \le T \le 100000), separated by a space. MM is prime, so its only divisors are 1 and itself, and 2M1000002 \le M \le 100000.

Each of the next TT lines has four integers aa, bb, cc, dd (0a,b,c,d<M0 \le a, b, c, d < M) separated by spaces, and they describe A=a+bi+cj+dkA = a + bi + cj + dk.

Output

For each AA, print on one line the four integers aa, bb, cc, dd of the restricted quaternion B=a+bi+cj+dkB = a + bi + cj + dk with AB=1AB = 1, separated by spaces. At most one such BB exists, so the answer is unique. If there is no such BB, print 0 four times, separated by spaces.