#include <bits/stdc++.h>
using namespace std;
int n, len, maxn = INT_MIN;
bool Not = false, is_not_Six = false;
string s;
int main(){
cin >> n;
for (int i = 0; i < n; i++){
cin >> s;
len = s.size();
Not = false;
is_not_Six = false;
maxn = INT_MIN;
for (int j = 0; j < len; j++){
if (s[j] == 'A' || s[j] == 'B' || s[j] == 'C' || s[j] == 'D' || s[j] == 'E' || s[j] == 'F'){
cout << "0 0 0 1" << endl;
Not = true;
break;
}
if (s[j] >= 'G') is_not_Six = true;
if (s[j] - '0' > maxn){
maxn = s[j] - '0';
}
}
if (Not) continue;
if (maxn <= 1) cout << "1 ";
else cout << "0 ";
if (maxn <= 7) cout << "1 ";
else cout << "0 ";
if (maxn <= 9) cout << "1 ";
else cout << "0 ";
if (!is_not_Six) cout << "1" << endl;
else cout << "0" << endl;
}
return 0;
}