#include <bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define F first
#define S second
#define rep(i, st, ed) for(ll i=st; i<ed; ++i)
#define repn(i, st, ed) for(ll i=st; i<=ed; ++i)
#define repb(i, ed, st) for(ll i=ed; i>=st; --i)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define PI acosl(-1.0)
#define mp(a, b) make_pair(a, b)
#define eps 1e-9
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int M = 1e9 + 7;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;
ll iv[N];
ll powM(ll a, ll b, ll M = M){ll res = 1;for(;b;a=a*a%M,b/=2) if(b&1) res=res*a%M;return res;}
ll nckbig(int n, int k){ll ans = 1;for(int i=1; i<=k; ++i){ans = ans*(n-i+1)%M*iv[i]%M;}return ans;}
ll caliv(){iv[1] = 1;for(int i=2; i<N; i++){iv[i] = M-M/i*iv[M%i]%M;}}
ll f1[N], f2[N];
ll calf(){f1[0] = f2[0] = 1;for(int i=2; i <N; ++i){f1[i] = f1[i-1]*i%M;f2[i] = f2[i-i]*iv[i]%M;}}
ll nck(int n, int k){return f1[n]*f2[n-k]%M*f2[k]%M;}
ll npk(int n, int k){return f1[n]*f2[n-k]%M;}
ll Rnck(int big){if(big){caliv();}else{calf();}}

int seg[26][4*N];
int arr[26][N];

ll up(ll a, ll b){
  return (a+b);
}
void build(ll v, ll tl, ll tr, int c)
    {
        if(tl == tr){
            seg[c][v] = arr[c][tl];
        }
        else
        {
            ll tm = (tl + tr) / 2;
            build(2*v, tl, tm, c);
            build(2*v+1, tm+1, tr, c);
            seg[c][v] = up(seg[c][2*v], seg[c][2*v+1]);
        }
    }

void update(ll v, ll tl, ll tr, ll pos,  int new_val, int c) 
    {
        if(tl == tr){
            seg[c][v] = new_val;
        }
        else
        {
            ll tm = (tl + tr) / 2;
            if(pos <= tm) update(v*2, tl, tm, pos, new_val, c);
            else update(v*2+1, tm+1, tr, pos, new_val, c);
            seg[c][v] = up(seg[c][v*2], seg[c][v*2+1]);
        }
    }
ll query(ll v, ll tl, ll tr, ll l, ll r, int c) {
        if(l > r) return 0;
        if(r < tl || l > tr) return 0;
        if(l == tl && r == tr){
            return seg[c][v];
        }
        ll tm = (tl + tr) / 2;
        ll ansl = query(2*v, tl, tm, l, min(r, tm), c);
        ll ansr = query(2*v+1, tm+1, tr, max(l, tm+1), r, c);
        return up(ansl, ansr);
    }

void solve()
{
  int n;
  cin>>n;
  string s;
  cin>>s;
  rep(i, 0, n){
    int c = s[i] - 'a';
    arr[c][i]++;
  }
  rep(i, 0, 26) build(1, 0, n-1, i);
  int q;
  cin>>q;
  while(q--){
    int c;
    cin>>c;
    if(c == 1){
      int pos;
      char ch;
      cin>>pos>>ch;
      pos--;
      int c = ch - 'a';
      int oldc = s[pos] - 'a';
      s[pos] = ch;
      //cerr<<s<<endl;
      update(1, 0, n-1, pos, 0, oldc);
      update(1, 0, n-1, pos, 1, c);
    }
    else{
      int l, r;
      cin>>l>>r;
      l--, r--;
      int ans= 0;
      rep(i, 0, 26){
        ans += (query(1, 0, n-1, l, r, i)>0?1:0);
        //cerr<<ans<<endl;
      }
      cout<<ans<<endl;
    }
  }
}


int main()
{
    FAST
    ll Tests = 1;
    //cin>>Tests;
    while(Tests--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 209820