#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <cctype>
#include <math.h>
#include <time.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define all(p) (p).begin(), (p).end()
#define fi first
#define se second
#define TASKNAME ""
//#define DEBUG
typedef long long ll;
const int N = 111111;
const int INF = int(1e9), mod = INF + 7;
string s;
vector <int> f[26];
int cnt[26], q[5];
void solve(int tt) {
cin >> s;
int n = s.length();
for (int i = 0; i < 26; ++i)
f[i].assign(n, 0);
for (int let = 0; let < 26; ++let) {
for (int i = 0; i < n; ++i) {
f[let][i] = (s[i] - 'A' == let);
if (i > 0) f[let][i] += f[let][i - 1];
}
}
cin >> q[tt];
while(q[tt] --> 0) {
char type; int l, r;
cin >> type >> l >> r;
if (type == 's') {
for (int i = l; i <= r; ++i)
cnt[s[i] - 'A']++;
int it = 0, it1 = l;
while(it < 26) {
if (cnt[it] == 0) it++;
else {
s[it1] = it + 'A';
--cnt[it];
++it1;
}
}
for (int let = 0; let < 26; ++let) {
for (int i = l; i <= r; ++i) {
f[let][i] = (s[i] - 'A' == let);
if (i > 0) f[let][i] += f[let][i - 1];
}
}
} else {
for (int let = 0; let < 26; ++let) {
printf("%d%c", f[let][r] - (l > 0 ? f[let][l - 1] : 0), let == 25 ? '\n' : ' ');
}
}
}
}
int main() {
int t;
cin >> t;
for (int tt = 1; tt <= t; ++tt) {
printf("Case #%d:\n", tt);
solve(tt);
}
return 0;
}
I2luY2x1ZGUgPGZ1bmN0aW9uYWw+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPG51bWVyaWM+CiNpbmNsdWRlIDxzdGRpby5oPgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGNjdHlwZT4KI2luY2x1ZGUgPG1hdGguaD4KI2luY2x1ZGUgPHRpbWUuaD4KI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AgICAgICAgICAgY250W3NbaV0gLSAnQSddKys7CgogICAgICAgICAgICBpbnQgaXQgPSAwLCBpdDEgPSBsOwoKICAgICAgICAgICAgd2hpbGUoaXQgPCAyNikgewoKICAgICAgICAgICAgICAgIGlmIChjbnRbaXRdID09IDApIGl0Kys7CiAgICAgICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBzW2l0MV0gPSBpdCArICdBJzsKICAgICAgICAgICAgICAgICAgICAtLWNudFtpdF07CiAgICAgICAgICAgICAgICAgICAgKytpdDE7CiAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICB9CgogICAgICAgICAgICBmb3IgKGludCBsZXQgPSAwOyBsZXQgPCAyNjsgKytsZXQpIHsKCiAgICAgICAgICAgICAgICBmb3IgKGludCBpID0gbDsgaSA8PSByOyArK2kpIHsKCiAgICAgICAgICAgICAgICAgICAgZltsZXRdW2ldID0gKHNbaV0gLSAnQScgPT0gbGV0KTsKICAgICAgICAgICAgICAgICAgICBpZiAoaSA+IDApIGZbbGV0XVtpXSArPSBmW2xldF1baSAtIDFdOwogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgfQoKICAgICAgICB9IGVsc2UgewoKICAgICAgICAgICAgZm9yIChpbnQgbGV0ID0gMDsgbGV0IDwgMjY7ICsrbGV0KSB7CgogICAgICAgICAgICAgICAgcHJpbnRmKCIlZCVjIiwgZltsZXRdW3JdIC0gKGwgPiAwID8gZltsZXRdW2wgLSAxXSA6IDApLCBsZXQgPT0gMjUgPyAnXG4nIDogJyAnKTsKCiAgICAgICAgICAgIH0KCiAgICAgICAgfQoKICAgIH0KfQoKaW50IG1haW4oKSB7CgogICAgaW50IHQ7CiAgICBjaW4gPj4gdDsKCiAgICBmb3IgKGludCB0dCA9IDE7IHR0IDw9IHQ7ICsrdHQpIHsKCiAgICAgICAgcHJpbnRmKCJDYXNlICMlZDpcbiIsIHR0KTsKICAgICAgICBzb2x2ZSh0dCk7CgogICAgfQoKCiAgICByZXR1cm4gMDsKfQ==