#!/bin/python3

import sys

def towerBreakers(n, m):
    if m == 1:
        return 2
    else:
        return 1 if n%2 == 1 else 2
    

if __name__ == "__main__":
    t = int(input().strip())
    for a0 in range(t):
        n, m = input().strip().split(' ')
        n, m = [int(n), int(m)]
        result = towerBreakers(n, m)
        print(result)

b7187f000005eda5541b2525d4362051eed8bb93
<mask token>

<mask token>


def towerBreakers(n, m):
    if m == 1:
        return 2
    else:
        return 1 if n % 2 == 1 else 2


<mask token>

<mask token>


def towerBreakers(n, m):
    if m == 1:
        return 2
    else:
        return 1 if n % 2 == 1 else 2


if __name__ == '__main__':
    t = int(input().strip())
    for a0 in range(t):
        n, m = input().strip().split(' ')
        n, m = [int(n), int(m)]
        result = towerBreakers(n, m)
        print(result)

import sys


def towerBreakers(n, m):
    if m == 1:
        return 2
    else:
        return 1 if n % 2 == 1 else 2


if __name__ == '__main__':
    t = int(input().strip())
    for a0 in range(t):
        n, m = input().strip().split(' ')
        n, m = [int(n), int(m)]
        result = towerBreakers(n, m)
        print(result)

#!/bin/python3

import sys

def towerBreakers(n, m):
    if m == 1:
        return 2
    else:
        return 1 if n%2 == 1 else 2
    

if __name__ == "__main__":
    t = int(input().strip())
    for a0 in range(t):
        n, m = input().strip().split(' ')
        n, m = [int(n), int(m)]
        result = towerBreakers(n, m)
        print(result)
