#include<iostream>
#include<string>
using namespace std;
int main()
{
int T;
cin>>T;
string n="";
for (int i=0;i<T;i++)
{
n="";
cin>>n;
bool flag=false;
if ((n[n.length()-1]-'0')%20)
{
cout<<0<<endl;
}
else if ((n[0]-'0')%20)
{
cout<<1<<endl;
}
else
{
for (int j=1;j<n.length()-1;j++)
{
if ((n[j]-'0')%2==0)
{
flag=true;
break;
}
}
if (flag)
{
cout<<2<<endl;
}
else
{
cout<<-1<<endl;
}
}
}
return 0;
}