#include<iostream>
#include<cmath>
using namespace std;
void solve()
{
int x, y;
double ans;
cin >> x >> y;
ans = sqrt(pow(0 - x, 2) + pow(0 - y, 2));
if (x == 0 && y == 0)
cout << 0 << "
";
else if (ans == (int)ans)
cout << 1 << "
";
else
cout << 2 << "
";
}
int main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}