#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
 
using namespace std;
 
int sun = 0;
void run(string st) {
    int bu = st.size() / 3;
 
    sun++;
 
    int s[14] = { 0 }, d[14] = { 0 }, h[14] = { 0 }, c[14] = { 0 };
 
    int ss = 13, dd = 13, hh = 13, cc = 13;
 
    char ch;
    int num;
    for (int i = 0; i < bu; i++) {
        ch = st[i * 3];
        string tmp = st.substr(i * 3 + 1, 2);
        num = stoi(tmp);
        if (ch == 'S')
            s[num]++;
        else if (ch == 'D')
            d[num]++;
        else if (ch == 'H')
            h[num]++;
        else if (ch == 'C')
            c[num]++;
    }
 
    for (int i = 1; i <= 13; i++) {
        if (s[i] >1  || d[i] >1 || h[i] >1 || c[i] >1) {
            cout << "#" << sun << " " "ERROR" << endl;
            return;
        }
        if (s[i] == 1) ss--;
        if (d[i] == 1) dd--;
        if (h[i] == 1) hh--;
        if (c[i] == 1) cc--;
    }
 
    cout << "#" << sun << " " << ss << " " << dd << " " << hh << " " << cc << endl;
 
}
 
int main() {
    int t;
    string st;
 
    cin >> t;
 
    for (int i = 0; i < t; i++) {
        cin >> st;
        run(st);
    }
 
    return 0;
}

+ Recent posts