#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
cin.ignore();
vector<string> r;
for (int i = 0; i < n; i++) {
string s;
getline(cin, s);
bool ib = true, io = true, is = true, ih = true;
for (char c : s) {
if (ib && c != '0' && c != '1') {
ib = false;
}
if (io && (c < '0' || c > '7')) {
io = false;
}
if (is && (c < '0' || c > '9')) {
is = false;
}
if (ih) {
if ((c < '0' || c > '9') && (c < 'A' || c > 'F')) {
ih = false;
}
}
if (!ib && !io && !is && !ih) {
break;
}
}
string result = "";
result += (ib ? '1' : '0');
result += ' ';
result += (io ? '1' : '0');
result += ' ';
result += (is ? '1' : '0');
result += ' ';
result += (ih ? '1' : '0');
r.push_back(result);
}
for (const string& res : r) {
cout << res << endl;
}
return 0;
}