#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;
int main()
{
long int n,i,j;cin>>n;
string s[n];
string max,k;
for(i=0;i<n;i++)
{
cin>>s[i];
}
for(i=0;i<n;i++)
{
for(j=0;j<s[i].size();j++)
{
if(s[i][j]>='G')
{
if(i!=n-1)
{
cout<<"0 0 0 0"<<'\n';
}
else{
cout<<"0 0 0 0";
}
goto FLAG;
}
}
for(j=0;j<s[i].size();j++)
{
if(s[i][j]>='A')
{
if(i!=n-1)
{
cout<<"0 0 0 1"<<'\n';
}
else{
cout<<"0 0 0 1";
}
goto FLAG;
}
}
for(j=0;j<s[i].size();j++)
{
max=s[i][0];
k=s[i][j];
if(stoi(k,0,16)>stoi(max,0,16))
{
max=s[i][j];
}
}
if(max=="9"||max=="8")
{
if(i!=n-1)
{
cout<<"0 0 1 1"<<'\n';
}
else{
cout<<"0 0 1 1";
}
}
if(max<="7"&&max>="2")
{
if(i!=n-1)
{
cout<<"0 1 1 1"<<'\n';
}
else{
cout<<"0 1 1 1";
}
}
if(max<="1"&&max>="0")
{
if(i!=n-1)
{
cout<<"1 1 1 1"<<'\n';
}
else{
cout<<"1 1 1 1";
}
}
FLAG:
continue;
}
}