#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 == m % 2)
			printf("2\n");
		else
			printf("1\n");
	}
}