#include<bits/stdc++.h>
using namespace std;
int t, c;
int main()
{
    int a[5], t; char q, w, e, r;
    string s;
    cin >> t;
    while (t--)
    {
        memset(a, 0, sizeof(a));
        cin >> s;
        printf("case #%d:\n", c++);
        for (int i = 0; i < s.size(); i++)
            if (s[i] == '!')
                a[i % 4]++;
            else
                s[i] == 'R' ? q = i : s[i] == 'B' ? w = i : s[i] == 'Y' ? e = i : r = i;
            printf("%d %d %d %d\n", a[q % 4], a[w % 4], a[e % 4], a[r % 4]);
    }
}
 
         
         
         
         
         
        
四个的时候需要特判
大佬……