#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
    ios_base::sync_with_stdio(false);;
    cin.tie(0);
    cout.tie(0); 
ll n,a,b,l,r,f,ans,i;
char c;
ll k1;
cin>>k1;
string s;
vector<set<ll>>v(26);
cin>>s;
for(i=0;i<s.size();i++)
{v[s[i]-'a'].insert(i);
}

cin>>n;
while(n--)
{cin>>a;
if(a==1)
{cin>>b>>c;
v[s[b-1]-'a'].erase(b-1);
v[c-'a'].insert(b-1);
s[b-1]=c;
}
else
{ans=0;
cin>>l>>r;
--l;
--r;
for(f=0;f<26;++f)
{auto it=v[f].lower_bound(l);
if(*it<=r && it!=v[f].end())
{ans+=1;
}
}
cout<<ans<<"\n";
}
}



return 0;
}