#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define gcd(a,b) __gcd(a,b)
#define sz sizeof
#define INF 1000000000000000000LL
#define ms memset
#define MAX
using namespace std;
int a[100010],tree[4*100010],lazy[4*100010];
void build(int node,int s,int d){
if(s==d){
//cout<<"node: "<<node<<" val: "<<a[s]<<endl;
tree[node] = a[s];
return;
}
int Left = node*2;
int Right = node*2 + 1;
int mid = (s+d)/2;
build(Left,s,mid);
build(Right,mid+1,d);
//update tree
tree[node] = tree[Left] + tree[Right];
}
void update(int node,int s,int d,int i,int j){
if(lazy[node]!=0){
if(lazy[node]%2==0){
// do nothing
}else{
tree[node] = (d-s+1) - tree[node];
}
if(s!=d){
lazy[node*2] += lazy[node];
lazy[node*2+1] += lazy[node];
}
lazy[node]=0;
}
//no overlap
if(s>j || d<i) return;
//total overlap
if(s>=i && d<=j){
tree[node] = (d-s+1) - tree[node];
if(s!=d){
lazy[node*2]++;
lazy[node*2+1]++;
}
return ;
}
//partial overlap
int Left = node*2;
int Right = node*2 + 1;
int mid = (s+d)/2;
update(Left,s,mid,i,j);
update(Right,mid+1,d,i,j);
//update tree
tree[node] = tree[Left] + tree[Right];
}
int query(int node,int s,int d,int i,int j){
if(lazy[node]!=0){
if(lazy[node]%2==0){
// do nothing
}else{
tree[node] = (d-s+1) - tree[node];
}
if(s!=d){
lazy[node*2] += lazy[node];
lazy[node*2+1] += lazy[node];
}
lazy[node]=0;
}
//no overlap
if(s>j || d<i){
return 0;
}
//total overlap
if(s>=i && d<=j){
return tree[node];
}
//partial overlap
int Left = node*2;
int Right = node*2 + 1;
int mid = (s+d)/2;
int p1=0,p2=0;
p1 = query(Left,s,mid,i,j);
p2 = query(Right,mid+1,d,i,j);
return p1+p2;
}
int main()
{
//freopen("a.in","r",stdin);
//freopen("out.txt","w",stdout);
//std::ios_base::sync_with_stdio(false);
int n,t,i,j,cases=1,q,u,v;
scanf("%d",&t);
getchar();
while(t--){
ms(a,0,sz(a));
ms(tree,0,sz(tree));
ms(lazy,0,sz(lazy));
char s[100010];
scanf("%s",&s);
for(i=0;i<strlen(s);i++){
a[i+1] = s[i]-'0';
}
n = strlen(s);
build(1,1,n);
printf("Case %d:\n",cases);cases++;
scanf("%d",&q);
getchar();
char ch;
while(q--){
scanf("%c",&ch);
if(ch=='I'){
scanf("%d %d",&u,&v);
update(1,1,n,u,v);
}else{
scanf("%d",&u);
int bit = query(1,1,n,u,u);
printf("%d\n",bit);
}
getchar();
}
}
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8c3RyaW5nLmg+CiNpbmNsdWRlIDxzdGRib29sLmg+CiNpbmNsdWRlIDxtYXRoLmg+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxzdGFjaz4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8c2V0PgojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIGxsIGxvbmcgbG9uZyBpbnQKI2RlZmluZSB1bGwgdW5zaWduZWQgbG9uZyBsb25nIGludAojZGVmaW5lIGdjZChhLGIpICAgIF9fZ2NkKGEsYikKI2RlZmluZSBzeiBzaXplb2YKI2RlZmluZSBJTkYgMTAwMDAwMDAwMDAwMDAwMDAwMExMCiNkZWZpbmUgbXMgbWVtc2V0CiNkZWZpbmUgTUFYCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKCmludCBhWzEwMDAxMF0sdHJlZVs0KjEwMDAxMF0sbGF6eVs0KjEwMDAxMF07CnZvaWQgYnVpbGQoaW50IG5vZGUsaW50IHMsaW50IGQpewogICAgaWYocz09ZCl7CiAgICAgICAgLy9jb3V0PDwibm9kZTogIjw8bm9kZTw8IiB2YWw6ICI8PGFbc108PGVuZGw7CiAgICAgICAgdHJlZVtub2RlXSA9IGFbc107CiAgICAgICAgcmV0dXJuOwogICAgfQogICAgaW50IExlZnQgPSBub2RlKjI7CiAgICBpbnQgUmlnaHQgPSBub2RlKjIgKyAxOwogICAgaW50IG1pZCA9IChzK2QpLzI7CiAgICBidWlsZChMZWZ0LHMsbWlkKTsKICAgIGJ1aWxkKFJpZ2h0LG1pZCsxLGQpOwoKICAgIC8vdXBkYXRlIHRyZWUKICAgIHRyZWVbbm9kZV0gPSB0cmVlW0xlZnRdICsgdHJlZVtSaWdodF07Cn0Kdm9pZCB1cGRhdGUoaW50IG5vZGUsaW50IHMsaW50IGQsaW50IGksaW50IGopewogICAgaWYobGF6eVtub2RlXSE9MCl7CiAgICAgICAgaWYobGF6eVtub2RlXSUyPT0wKXsKICAgICAgICAgICAgLy8gZG8gbm90aGluZwogICAgICAgIH1lbHNlewogICAgICAgICAgICB0cmVlW25vZGVdID0gKGQtcysxKSAtIHRyZWVbbm9kZV07CiAgICAgICAgfQoKICAgICAgICBpZihzIT1kKXsKICAgICAgICAgICAgbGF6eVtub2RlKjJdICs9IGxhenlbbm9kZV07CiAgICAgICAgICAgIGxhenlbbm9kZSoyKzFdICs9IGxhenlbbm9kZV07CiAgICAgICAgfQogICAgICAgIGxhenlbbm9kZV09MDsKICAgIH0KCiAgICAvL25vIG92ZXJsYXAKICAgIGlmKHM+aiB8fCBkPGkpIHJldHVybjsKICAgIC8vdG90YWwgb3ZlcmxhcAogICAgaWYocz49aSAmJiBkPD1qKXsKICAgICAgICB0cmVlW25vZGVdID0gKGQtcysxKSAtIHRyZWVbbm9kZV07CgogICAgICAgIGlmKHMhPWQpewogICAgICAgICAgICBsYXp5W25vZGUqMl0rKzsKICAgICAgICAgICAgbGF6eVtub2RlKjIrMV0rKzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIDsKICAgIH0KICAgIC8vcGFydGlhbCBvdmVybGFwCiAgICBpbnQgTGVmdCA9IG5vZGUqMjsKICAgIGludCBSaWdodCA9IG5vZGUqMiArIDE7CiAgICBpbnQgbWlkID0gKHMrZCkvMjsKICAgIHVwZGF0ZShMZWZ0LHMsbWlkLGksaik7CiAgICB1cGRhdGUoUmlnaHQsbWlkKzEsZCxpLGopOwoKICAgIC8vdXBkYXRlIHRyZWUKICAgIHRyZWVbbm9kZV0gPSB0cmVlW0xlZnRdICsgdHJlZVtSaWdodF07Cn0KaW50IHF1ZXJ5KGludCBub2RlLGludCBzLGludCBkLGludCBpLGludCBqKXsKICAgIGlmKGxhenlbbm9kZV0hPTApewogICAgICAgIGlmKGxhenlbbm9kZV0lMj09MCl7CiAgICAgICAgICAgIC8vIGRvIG5vdGhpbmcKICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgdHJlZVtub2RlXSA9IChkLXMrMSkgLSB0cmVlW25vZGVdOwogICAgICAgIH0KCiAgICAgICAgaWYocyE9ZCl7CiAgICAgICAgICAgIGxhenlbbm9kZSoyXSArPSBsYXp5W25vZGVdOwogICAgICAgICAgICBsYXp5W25vZGUqMisxXSArPSBsYXp5W25vZGVdOwogICAgICAgIH0KICAgICAgICBsYXp5W25vZGVdPTA7CiAgICB9CgogICAgLy9ubyBvdmVybGFwCiAgICBpZihzPmogfHwgZDxpKXsKICAgICAgICByZXR1cm4gMDsKICAgIH0KICAgIC8vdG90YWwgb3ZlcmxhcAogICAgaWYocz49aSAmJiBkPD1qKXsKICAgICAgICByZXR1cm4gdHJlZVtub2RlXTsKICAgIH0KICAgIC8vcGFydGlhbCBvdmVybGFwCiAgICBpbnQgTGVmdCA9IG5vZGUqMjsKICAgIGludCBSaWdodCA9IG5vZGUqMiArIDE7CiAgICBpbnQgbWlkID0gKHMrZCkvMjsKICAgIGludCBwMT0wLHAyPTA7CiAgICBwMSA9IHF1ZXJ5KExlZnQscyxtaWQsaSxqKTsKICAgIHAyID0gcXVlcnkoUmlnaHQsbWlkKzEsZCxpLGopOwogICAgcmV0dXJuIHAxK3AyOwp9CgppbnQgbWFpbigpCnsKICAgIC8vZnJlb3BlbigiYS5pbiIsInIiLHN0ZGluKTsKICAgIC8vZnJlb3Blbigib3V0LnR4dCIsInciLHN0ZG91dCk7CiAgICAvL3N0ZDo6aW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBpbnQgbix0LGksaixjYXNlcz0xLHEsdSx2OwogICAgc2NhbmYoIiVkIiwmdCk7CiAgICBnZXRjaGFyKCk7CiAgICB3aGlsZSh0LS0pewogICAgICAgIG1zKGEsMCxzeihhKSk7CiAgICAgICAgbXModHJlZSwwLHN6KHRyZWUpKTsKICAgICAgICBtcyhsYXp5LDAsc3oobGF6eSkpOwogICAgICAgIGNoYXIgc1sxMDAwMTBdOwogICAgICAgIHNjYW5mKCIlcyIsJnMpOwogICAgICAgIGZvcihpPTA7aTxzdHJsZW4ocyk7aSsrKXsKICAgICAgICAgICAgYVtpKzFdID0gc1tpXS0nMCc7CiAgICAgICAgfQogICAgICAgIG4gPSBzdHJsZW4ocyk7CiAgICAgICAgYnVpbGQoMSwxLG4pOwogICAgICAgIHByaW50ZigiQ2FzZSAlZDpcbiIsY2FzZXMpO2Nhc2VzKys7CiAgICAgICAgc2NhbmYoIiVkIiwmcSk7CiAgICAgICAgZ2V0Y2hhcigpOwogICAgICAgIGNoYXIgY2g7CiAgICAgICAgd2hpbGUocS0tKXsKICAgICAgICAgICAgc2NhbmYoIiVjIiwmY2gpOwogICAgICAgICAgICBpZihjaD09J0knKXsKICAgICAgICAgICAgICAgIHNjYW5mKCIlZCAlZCIsJnUsJnYpOwogICAgICAgICAgICAgICAgdXBkYXRlKDEsMSxuLHUsdik7CiAgICAgICAgICAgIH1lbHNlewogICAgICAgICAgICAgICAgc2NhbmYoIiVkIiwmdSk7CiAgICAgICAgICAgICAgICBpbnQgYml0ID0gcXVlcnkoMSwxLG4sdSx1KTsKICAgICAgICAgICAgICAgIHByaW50ZigiJWRcbiIsYml0KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBnZXRjaGFyKCk7CiAgICAgICAgfQogICAgfQoKCgogICAgcmV0dXJuIDA7Cn0K