#include<bits/stdc++.h>
using namespace std;
int main(){
string s[1010];
int n;
cin>>n;
for(int i=0;i<n;i++)cin>>s[i];
for(int i=0;i<n;i++){
bool f=true;
for(int j=0;j<s[i].size();j++){
if(s[i][j]!='1'&&s[i][j]!='0'){
cout<<0<<' ';
f=false;
break;
}
}
if(f)cout<<1<<" ";
f=true;
for(int k=0;k<s[i].size();k++){
if(s[i][k]!='0'&&s[i][k]!='1'&&s[i][k]!='2'&&s[i][k]!='3'&&s[i][k]!='4'&&s[i][k]!='5'&&s[i][k]!='6'&&s[i][k]!='7'){
cout<<0<<" ";
f=false;
break;
}
}
if(f)cout<<1<<" ";
f=true;
for(int k=0;k<s[i].size();k++){
if(s[i][k]!='0'&&s[i][k]!='1'&&s[i][k]!='2'&&s[i][k]!='3'&&s[i][k]!='4'&&s[i][k]!='5'&&s[i][k]!='6'&&s[i][k]!='7'&&s[i][k]!='8'&&s[i][k]!='9'){
cout<<0<<" ";
f=false;
break;
}
}
if(f)cout<<1<<" ";
f=true;
for(int k=0;k<s[i].size();k++){
if(s[i][k]!='0'&&s[i][k]!='1'&&s[i][k]!='2'&&s[i][k]!='3'&&s[i][k]!='4'&&s[i][k]!='5'&&s[i][k]!='6'&&s[i][k]!='7'&&s[i][k]!='8'&&s[i][k]!='9'&&s[i][k]!='A'&&s[i][k]!='B'&&s[i][k]!='C'&&s[i][k]!='D'&&s[i][k]!='E'&&s[i][k]!='F'){
cout<<0;
f=false;
break;
}
}
if(f)cout<<1;
if(i!=n-1)cout<<endl;
}
return 0;
}