#include <stdio.h>
#include <iostream>
using namespace std;
int main ()
{
freopen("ROOK.in","r",stdin);
int t;
cin >> t;
for (int i=0; i < t; i++)
{
	int x,y;
	cin >> x >> y;
	if (x==1 && y == 1) 
	{
		cout << '0' << endl;
	}
	else if (x == y && x != 1)
	{
		cout << '2' << endl;
	}
	else cout << '1' << endl;
}
}