#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 100010;
struct Node
{
int letter[26];
char c;
};
Node t[4 * N + 1];
string s;
Node join(Node l, Node r)
{
Node node;
for(int i = 0; i < 26; i++)
{
node.letter[i] = l.letter[i] + r.letter[i];
}
return node;
}
void build(int p, int l, int r)
{
if(l == r)
{
t[p].letter[s[l] - 'A'] = 1;
t[p].c = s[l];
return;
}
int mid = (l + r) / 2;
build(2 * p, l, mid);
build(2 * p + 1, mid + 1, r);
t[p] = join(t[2 * p], t[2 * p + 1]);
}
void update(int p, int l, int r, int i, char c)
{
char cc = t[p].c;
if(l == r)
{
t[p].letter[cc - 'A'] = 0;
t[p].letter[c - 'A'] = 1;
t[p].c = c;
return;
}
int mid = (l + r) / 2;
if(i <= mid)
update(2 * p, l, mid, i, c);
else
update(2 * p + 1, mid + 1, r, i, c);
t[p] = join(t[2 * p], t[2 * p + 1]);
}
Node query(int p, int l, int r, int i, int j)
{
Node node;
memset(node.letter, 0, sizeof(node.letter));
if(i > r || j < l || l > r)
return node;
if(i <= l && r <= j)
return t[p];
int mid = (l + r) / 2;
Node x, y;
x = query(2 * p, l, mid, i, j);
y = query(2 * p + 1, mid + 1, r, i, j);
return join(x, y);
}
int main()
{
int tt, q, l, r;
char op;
int tc = 1;
scanf("%d", &tt);
while(tt--)
{
printf("Case #%d:\n", tc++);
cin >> s;
cin >> q;
memset(t, 0, sizeof(t));
build(1, 0, s.size() - 1);
while(q--)
{
cin >> op >> l >> r;
if(op == 's') {
sort(s.begin() + l, s.begin() + r + 1);
for(int i = l; i <= r; i++)
update(1, 0, s.size() - 1, i, s[i]);
}
else
{
Node node = query(1, 0, s.size() - 1, l, r);
for(int i = 0; i < 26; i++)
printf("%d%c", node.letter[i], (i == 25) ? '\n' : ' ');
}
}
}
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8Y3N0cmluZz4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTiA9IDEwMDAxMDsKCnN0cnVjdCBOb2RlCnsKICAgIGludCBsZXR0ZXJbMjZdOwogICAgY2hhciBjOwp9OwoKTm9kZSB0WzQgKiBOICsgMV07CnN0cmluZyBzOwoKTm9kZSBqb2luKE5vZGUgbCwgTm9kZSByKQp7CiAgICBOb2RlIG5vZGU7CiAgICAKICAgIGZvcihpbnQgaSA9IDA7IGkgPCAyNjsgaSsrKQogICAgewogICAgICAgIG5vZGUubGV0dGVyW2ldID0gbC5sZXR0ZXJbaV0gKyByLmxldHRlcltpXTsKICAgIH0KICAgIAogICAgcmV0dXJuIG5vZGU7Cn0KCnZvaWQgYnVpbGQoaW50IHAsIGludCBsLCBpbnQgcikKewogICAgaWYobCA9PSByKQogICAgewogICAgICAgIHRbcF0ubGV0dGVyW3NbbF0gLSAnQSddID0gMTsKICAgICAgICB0W3BdLmMgPSBzW2xdOwogICAgICAgIAogICAgICAgIHJldHVybjsKICAgIH0KICAgIAogICAgaW50IG1pZCA9IChsICsgcikgLyAyOwogICAgCiAgICBidWlsZCgyICogcCwgbCwgbWlkKTsKICAgIGJ1aWxkKDIgKiBwICsgMSwgbWlkICsgMSwgcik7CiAgICAKICAgIHRbcF0gPSBqb2luKHRbMiAqIHBdLCB0WzIgKiBwICsgMV0pOwogICAgCn0KCnZvaWQgdXBkYXRlKGludCBwLCBpbnQgbCwgaW50IHIsIGludCBpLCBjaGFyIGMpCnsKICAgIGNoYXIgY2MgPSB0W3BdLmM7CiAgICAKICAgIGlmKGwgPT0gcikKICAgIHsKICAgICAgICB0W3BdLmxldHRlcltjYyAtICdBJ10gPSAwOwogICAgICAgIHRbcF0ubGV0dGVyW2MgLSAnQSddID0gMTsKICAgICAgICB0W3BdLmMgPSBjOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIAogICAgaW50IG1pZCA9IChsICsgcikgLyAyOwogICAgCiAgICAKICAgIGlmKGkgPD0gbWlkKQogICAgICAgIHVwZGF0ZSgyICogcCwgbCwgbWlkLCBpLCBjKTsKICAgIGVsc2UKICAgICAgICB1cGRhdGUoMiAqIHAgKyAxLCBtaWQgKyAxLCByLCBpLCBjKTsKICAgIAogICAgdFtwXSA9IGpvaW4odFsyICogcF0sIHRbMiAqIHAgKyAxXSk7Cn0KCk5vZGUgcXVlcnkoaW50IHAsIGludCBsLCBpbnQgciwgaW50IGksIGludCBqKQp7CiAgICBOb2RlIG5vZGU7CiAgICBtZW1zZXQobm9kZS5sZXR0ZXIsIDAsIHNpemVvZihub2RlLmxldHRlcikpOwogICAgCiAgICBpZihpID4gciB8fCBqIDwgbCAgfHwgbCA+IHIpCiAgICAgICAgcmV0dXJuIG5vZGU7CiAgICAgICAgCiAgICBpZihpIDw9IGwgJiYgciA8PSBqKQogICAgICAgIHJldHVybiB0W3BdOwogICAgICAgIAogICAgaW50IG1pZCA9IChsICsgcikgLyAyOwogICAgCiAgICBOb2RlIHgsIHk7CiAgICB4ID0gcXVlcnkoMiAqIHAsIGwsIG1pZCwgaSwgaik7CiAgICB5ID0gcXVlcnkoMiAqIHAgKyAxLCBtaWQgKyAxLCByLCBpLCBqKTsKICAgIAogICAgcmV0dXJuIGpvaW4oeCwgeSk7Cn0KCmludCBtYWluKCkKewogICAgaW50IHR0LCBxLCBsLCByOwogICAgY2hhciBvcDsKICAgIAogICAgaW50IHRjID0gMTsKICAgIAogICAgc2NhbmYoIiVkIiwgJnR0KTsKICAgIAogICAgd2hpbGUodHQtLSkKICAgIHsKICAgICAgICBwcmludGYoIkNhc2UgIyVkOlxuIiwgdGMrKyk7CiAgICAgICAgY2luID4+IHM7CiAgICAgICAgY2luID4+IHE7CiAgICAgICAgCiAgICAgICAgbWVtc2V0KHQsIDAsIHNpemVvZih0KSk7CiAgICAgICAgYnVpbGQoMSwgMCwgcy5zaXplKCkgLSAxKTsKICAgICAgICAKICAgICAgICB3aGlsZShxLS0pCiAgICAgICAgewogICAgICAgICAgICBjaW4gPj4gb3AgPj4gbCA+PiByOwogICAgICAgICAgICAKICAgICAgICAgICAgaWYob3AgPT0gJ3MnKSB7CiAgICAgICAgICAgICAgICBzb3J0KHMuYmVnaW4oKSArIGwsIHMuYmVnaW4oKSArIHIgKyAxKTsKICAgICAgICAgICAgICAgIGZvcihpbnQgaSA9IGw7IGkgPD0gcjsgaSsrKQogICAgICAgICAgICAgICAgICAgIHVwZGF0ZSgxLCAwLCBzLnNpemUoKSAtIDEsIGksIHNbaV0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgTm9kZSBub2RlID0gcXVlcnkoMSwgMCwgcy5zaXplKCkgLSAxLCBsLCByKTsKICAgICAgICAgICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCAyNjsgaSsrKSAKICAgICAgICAgICAgICAgICAgICBwcmludGYoIiVkJWMiLCBub2RlLmxldHRlcltpXSwgKGkgPT0gMjUpID8gJ1xuJyA6ICcgJyk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICAKICAgIHJldHVybiAwOwp9