#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x = 1, y = 1, z = 1, f = 1;
string a;
cin >> n;
for (int i = 1; i <= n; i++) {
long long n, x = 1, y = 1, z = 1, f = 1;
cin >> a;
for (int i = 0; i < a.size(); i++) {
if (a[i] >= 'A' && a[i] <= 'Z') {
x = y = z = 0;
}
if (a[i] >= '8') {
y = 0;
}
if (a[i] >= '2') {
x = 0;
}
}
cout << x << ' ' << y << ' ' << z << ' ' << f << endl;
}
return 0;
}