Coin Toss Game

No attempts yetTime limit1sMemory limit256 MB

Problem

Younghee and Dongsu play a coin toss game. The game runs for KK rounds under these rules.

  1. In one round each player tosses a coin once, and Younghee always tosses first.
  2. A head scores 1 point and a tail scores nothing.
  3. After every single toss the players check whether the result is already settled. If one player would stay below the opponent's current score even after getting a head on every toss they have left, the game stops right there, even in the middle of a round.

Let MM be Younghee's score and NN be Dongsu's score at the moment the game stops. Picking any two integers MM and NN between 00 and KK does not give a pair that a game can actually produce. For K=2K = 2, the nine pairs split like this.

MMNNCan be the scores of Younghee and Dongsu
00Possible
01Possible
02Impossible
10Possible
11Possible
12Possible
20Possible
21Possible
22Possible

Here is why (M,N)=(0,2)(M, N) = (0, 2) is impossible. Dongsu needs a head in both rounds to reach 2 points, so he already holds 1 point when the second round starts. Younghee has to toss a tail to stay at 0 points, and at that moment she has no tosses left, so she can never pass Dongsu. Rule 3 stops the game at 0 and 1, and Dongsu never tosses his second coin.

Given MM and NN, decide whether the two numbers can be Younghee's and Dongsu's scores once the game has ended.

Input

The first line has the number of rounds KK (1K10001 \le K \le 1000).

The second line has the number of queries CC (1C1000001 \le C \le 100000).

Each of the next CC lines has two integers MM and NN separated by a space (0M,NK0 \le M, N \le K).

Output

Print CC lines. On the ii-th line print 1 if the MM and NN of the ii-th query can be the scores of Younghee and Dongsu once the game has ended, and 0 otherwise.