#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define vi vector<int>
const int N = 1e5 + 5;
int n,q,v[N],root, nxt[N];
vector<int> b[400];
std::map<int, vi> save;
void runNxt()
{
for (int i = 0; i < n; ++i)
{
save[v[i]].push_back(i);
}
for (int i = 0; i < n; ++i)
{
int idx = *upper_bound(all(save[v[i]]), i);
nxt[i] = idx?idx:n + 1;
}
}
int main(int argc, char const *argv[])
{
string s; cin>>s;
n = s.size();
root=sqrt(n);
int ct = (n + root - 1) / root;
for(int i=0; i<n; ++i)
v[i] = s[i] - 'a';
runNxt();
for(int i=0; i<n; ++i)
b[i/root].push_back(nxt[i]);
for(int i=0; i<ct; ++i)
sort(b[i].begin(), b[i].end());
int q; scanf("%d", &q);
int T;
for(int i, l, r; i < q; ++i)
{
scanf("%d", &T);
if(T==2)
{
scanf("%d%d",&l,&r);
--l;--r;
int ans=0;
for(int j=l; j<=r; ++j)
{
if(j%root==0 && j+root-1<=r)
{
ans+= upper_bound(b[j/root].begin(), b[j/root].end(), r) - b[j/root].begin();
j+=root-1;
}
else if(nxt[j] > r)
{
++ans;
}
}
printf("%d\n", ans);
}
else
{
char c;
scanf("%d %c",&l,&c);
--l;
v[l] = c - 'a';
int bucket = l / root;
b[bucket].clear();
for(int j=bucket*root; j<n && j<(bucket + 1)*root; ++j)
b[bucket].push_back(*upper_bound(all(save[v[j]]), nxt[j]));
sort(b[bucket].begin(), b[bucket].end());
}
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBhbGwodikgKCh2KS5iZWdpbigpKSwoKHYpLmVuZCgpKQojZGVmaW5lIHZpIHZlY3RvcjxpbnQ+Cgpjb25zdCBpbnQgTiA9IDFlNSArIDU7CgppbnQgbixxLHZbTl0scm9vdCwgbnh0W05dOwoKdmVjdG9yPGludD4gYls0MDBdOwoKc3RkOjptYXA8aW50LCB2aT4gc2F2ZTsKCnZvaW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