403375: GYM101147 A The game of Osho
Description
Faheem and Faheema love to play what they call the game of Osho, in this game they choose a number N randomly, the first player subtracts a non-zero number Bk1 less than or equal to N from N, then the second player subtracts number Bk2 (where B is given and ki is a non negative integer number), then again the first and so on until one of the players loses when he/she can't make any move. In other words, when it's a player's turn and N equals 0. For example let's see this game when B=2 and N=3. The first player Faheem can subtract 1 or 2 the optimal move here is 1, N now equals 2. In her turn Faheema subtract 2 because 1 will make Faheem win, Faheem now can't play any move and he loses.
After a while they found that this game is boring so they decided to upgrade it, their version combines multiple subgames of the form (Bi, Ni) and the player can choose which of them he wants to play his move in, a player loses when he/she can't make a move.
Given the subgames, your job is to determine which player wins the whole game assuming that both players play optimally.
InputThe first line contains T, the number of test cases. The next T lines contain G (1 ≤ G ≤ 100) the number of subgames and then follows G pairs of integers (1 ≤ Bi, Ni ≤ 1, 000, 000, 000) describing each subgame.
OutputFor each test case print 1 if the first player wins the game, or 2 if the second wins.
ExamplesInput3Output
1 2 3
1 7 3
2 6 11 3 2
2
1
2