#include<bits/stdc++.h>
using namespace std;
int main (){
int n;
string s;
cin>>n;
for (int i=1;i<=n;i++) {
bool b[4]={1,1,1,1};
cin>>s;
for (int j=0;j<=s.size();j++) {
if (s[j]>=2) {
b[0]=0;
}
if (s[j]>=8) {
b[1]=0;
}
if (s[j]>=10) {
b[2]=0;
}
if (s[j]>='G'){
b[3]=0;
}
}
cout<<b[0]<<" "<<b[1]<<" "<<b[2]<<" "<<b[3]<<endl;
}
return 0;
}