#include <stdio.h>
int main()
{
	int t, n, m, i, f1, f2;
	freopen("rook.in", "r", stdin);
	scanf("%d", &t);
	for (i = 0; i < t; i++)
	{
		scanf("%d%d", &n, &m);
		if (n == 1 && m == 1)
			printf("0\n");
		else
		{
			if (n % 2 > 0)
				f1 = 1;
			else
				f1 = 0;
			if (m % 2 > 0)
				f2 = 1;
			else
				f2 = 0;
			if (f1 == f2)
				printf("2\n");
			else
				printf("1\n");
		}
	}
}