#include using namespace std; #include using namespace atcoder; #define rep(i, n) for(int i=0;i<(n);++i) #define rep1(i, n) for(int i=1;i<=(n);i++) #define ll long long using mint = modint998244353; using P = pair; using lb = long double; using T = tuple; #ifdef LOCAL # include # define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define dbg(...) (static_cast(0)) #endif int op(int a, int b){ return a+b; } int e(){ return 0; } int main() { int n; string s; cin >> n >> s; int q; cin >> q; segtree seg(n); vector> cnt(26, seg); vector> sum(26, seg); vector> st(26); rep(i,n){ cnt[s[i]-'A'].set(i,1); sum[s[i]-'A'].set(i,i); st[s[i]-'A'].insert(i); } rep(_,q){ int t; cin >> t; if(t==1){ int x; char c; cin >> x >> c; --x; st[s[x]-'A'].erase(x); cnt[s[x]-'A'].set(x,0); sum[s[x]-'A'].set(x,0); s[x] = c; cnt[s[x]-'A'].set(x,1); sum[s[x]-'A'].set(x,x); st[s[x]-'A'].insert(x); }else{ int l, r; cin >> l >> r; --l; ll ans = 0; rep(i,26){ ll c = cnt[i].prod(l, r); if(c<2) continue; auto it = st[i].lower_bound(l); ll s = sum[i].prod(l,r) - *it; ans += (c-1)*(r-1); ans -= s - (c-1)*(c-2)/2; } cout << ans << endl; } } return 0; }