// In The Name of GOD
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>
#include <time.h>
using namespace std;
#define int64 long long
#define P pair<int, int>
#define Mod 1000000007LL
int n, w, q, l, r,a[100002],b[26]; char c;
string s;
int main(){
cin >> w;
for (int o = 1; o <= w; o++)
{
cout << "Case #" << o << ":"<<endl;
cin >> s >> q;
for (int i = 0; i < s.size(); i++)
a[i] = s[i];
for (int i = 0; i < q; i++)
{
cin >> c >> l >> r;
if (c == 'g')
{
for (int j = l; j <= r; j++)
b[a[j] - 'A']++;
for (int j = 0; j < 25; j++)
cout << b[j] << ' ';
cout << b[25] << endl;
memset(b, 0, sizeof b);
}
else
sort(a + l, a +r+1);
}
}
return 0;
}
///Havij vru!
Ly8gSW4gVGhlIE5hbWUgb2YgR09ECiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPG1lbW9yeS5oPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDxjbWF0aD4KI2luY2x1ZGUgPGxpc3Q+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDx0aW1lLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBpbnQ2NCBsb25nIGxvbmcKI2RlZmluZSBQIHBhaXI8aW50LCBpbnQ+CiNkZWZpbmUgTW9kIDEwMDAwMDAwMDdMTAoKaW50IG4sIHcsIHEsIGwsIHIsYVsxMDAwMDJdLGJbMjZdOyBjaGFyIGM7CnN0cmluZyBzOwppbnQgbWFpbigpewoKCWNpbiA+PiB3OwoJZm9yIChpbnQgbyA9IDE7IG8gPD0gdzsgbysrKQoJewoJCWNvdXQgPDwgIkNhc2Ug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