Trails

No attempts yetTime limit1sMemory limit128 MB

Problem

Byteasar is still playing with his plotter and printing bytecurves. (Recall that a bytecurve of order nn consists of 2n2^n segments, each of length 2\sqrt{2}. The first segment connects the points (0,0)(0, 0) and (1,1)(1, 1), and between any two consecutive segments the pen turns by 9090^\circ: the ii-th turn (for 1i<2n1 \le i < 2^n) is to the right if and only if i=2k(1+2l)i = 2^k(1 + 2l) for some non-negative integer kk and odd ll.)

Byteasar has noticed that he can draw beautiful trails with his plotter. Before starting the plotter, he sticks a piece of paper tape on the paper so that it covers the rectangle whose opposite corners are (x1,y)(x_1, y) and (x2,y+1)(x_2, y + 1). After the plotter finishes, he peels off the tape and admires the trails left on it. A trail is any connected curve of positive length drawn on the tape.

While waiting for the plotter to finish, Byteasar wonders how many trails will end up on the tape. Help him answer this question.

Input

The first line contains two integers nn and mm (1n,m20001 \le n, m \le 2000): the order of the bytecurve and the number of queries. Each of the next mm lines contains three integers x1x_1, x2x_2 and yy (109x1,x2,y109-10^9 \le x_1, x_2, y \le 10^9, x1<x2x_1 < x_2), describing one glued tape.

Output

Print mm lines, one per query. Each line contains a single integer: the number of trails drawn on the corresponding tape.

Hint