#include<bits/stdc++.h>
using namespace std;
void f(string s){
bool a=false;//非法
bool b=false;//16
bool c=false;//10
bool d=false;//8
bool e=false;//2
for(int i=0;i<s.size();i++){
if(s[i]>='A'&&s[i]<='F'){
b=1;c=0;d=0;e=0;
}else if(s[i]>='8'&&s[i]<='9'){
c=1;d=0;e=0;
}else if(s[i]>='2'&&s[i]<='7'){
d=1;e=0;
}else if(s[i]=='1'||s[i]=='0'){
e=1;
}else{
cout<<0<<' '<<0<<' '<<0<<' '<<0;return;
}
}
cout<<e<<" "<<d<<" "<<c<<" "<<b<<endl;
return;
}
int main(){
bool a,b,c,d;
int n;
string s;
cin>>n;
for(int i=0;i<n;i++){
cin>>s;
f(s);
}
return 0;
}