#include<bits/stdc++.h>
using namespace std;
int n,f1,f2,k;
string tmp;
int main() {
cin>>n;
for(int i=1; i<=n; i++) {
cin>>tmp;
f1=0;
for(int j=0;j<tmp.size();j++){
if(tmp[j]>='A'&&tmp[j]<='Z'){
cout<<"0 0 0 1\n";
f1=1;
break;
}
}
if(f1)continue;
for(int j=0;j<tmp.size();j++){
if(tmp[j]>='2'){
break;
}if(j==tmp.size()-1){
cout<<"1 1 1 1\n";
f1=1;
}
}
if(f1)continue;
for(int j=0;j<tmp.size();j++){
if(tmp[j]>='8'){
break;
}if(j==tmp.size()-1){
cout<<"0 1 1 1\n";
f1=1;
}
}
if(f1)continue;
for(int j=0;j<tmp.size();j++){
if(tmp[j]>='10'){
break;
}if(j==tmp.size()-1){
cout<<"0 0 1 1\n";
f1=1;
}
}
if(f1)continue;
cout<<"0 0 0 0\n";
}
return 0;
}