#include<bits/stdc++.h>
using namespace std;
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)
#define MOD 1000000007
#define MX 100010
int main()
{
int sl, tc,kk=1, n, arr[30];
string s;
cin>>tc;
while(tc--)
{
CLR(arr);
cin>>s;
sl=s.length();
stack<char>st;
st.push(s[0]);
st.push(s[1]);
for(int i=2;i<sl-1;i++)
{
char tmp=st.top();
if(st.top()==s[i])
{
arr[s[i]-'A']++;
st.pop();
arr[st.top()-'A']++;
}
else st.push(s[i]);
}
cout<<"Case "<<kk++<<endl;
for(int i=0;i<26;i++)
if(arr[i])
cout<<char(i+'A')<<" = "<<arr[i]<<endl;
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgU0VUKGEpIG1lbXNldChhLC0xLHNpemVvZihhKSkKI2RlZmluZSBDTFIoYSkgbWVtc2V0KGEsMCxzaXplb2YoYSkpCiNkZWZpbmUgUEkgYWNvcygtMS4wKQoKI2RlZmluZSBNT0QgMTAwMDAwMDAwNwojZGVmaW5lIE1YIDEwMDAxMAoKaW50IG1haW4oKQp7CiAgICBpbnQgc2wsIHRjLGtrPTEsIG4sIGFyclszMF07CiAgICBzdHJpbmcgczsKICAgIGNpbj4+dGM7IAogICAgd2hpbGUodGMtLSkKICAgIHsKICAgICAgICBDTFIoYXJyKTsKICAgICAgICBjaW4+PnM7CiAgICAgICAgc2w9cy5sZW5ndGgoKTsKICAgICAgICBzdGFjazxjaGFyPnN0OwogICAgICAgIHN0LnB1c2goc1swXSk7CiAgICAgICAgc3QucHVzaChzWzFdKTsKICAgICAgICBmb3IoaW50IGk9MjtpPHNsLTE7aSsrKQogICAgICAgIHsKICAgICAgICAgICAgY2hhciB0bXA9c3QudG9wKCk7CiAgICAgICAgICAgIGlmKHN0LnRvcCgpPT1zW2ldKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBhcnJbc1tpXS0nQSddKys7CiAgICAgICAgICAgICAgICBzdC5wb3AoKTsKICAgICAgICAgICAgICAgIGFycltzdC50b3AoKS0nQSddKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSBzdC5wdXNoKHNbaV0pOwogICAgICAgIH0KICAgICAgICBjb3V0PDwiQ2FzZSAiPDxraysrPDxlbmRsOwogICAgICAgIGZvcihpbnQgaT0wO2k8MjY7aSsrKQogICAgICAgICAgICBpZihhcnJbaV0pCiAgICAgICAgICAgICAgICBjb3V0PDxjaGFyKGkrJ0EnKTw8IiA9ICI8PGFycltpXTw8ZW5kbDsKICAgIH0KICAgIHJldHVybiAwOwp9