#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

auto f = [](ll a,ll b){return a+b;};
auto g = [](ll a,ll b){return b;};

template <class T>
class SegmentTree{
  ll N;
  vector<T> data;
  vector<T> lazy;
  T def;
  function<T(T,T)> operation;
  function<T(T,T)> update;
  public:
  SegmentTree(size_t _N,T _def,function<T(T,T)> _operaition,function<T(T,T)> _update):def(_def),operation(_operaition),update(_update){
          N = 1;
          while(N < _N){
              N *= 2;
          }
          data = vector<T>(2*N-1,def);
          lazy = vector<T>(2*N-1,0);
  }

  void change(ll i,ll x){
      i += N-1;
      data[i] = update(data[i],x);
      while(i > 0){
          i = (i-1)/2;
          data[i] = oparaition(data[i*2+1],data[i*2+2]);
      }
  }

  void eval(ll k,ll l,ll r){
      if(lazy[k] != 0){
          data[k] += lazy[k];
          if(r - l > 1){
              lazy[k*2+1] += (lazy[k] / 2);
              lazy[k*2+2] += (lazy[k] / 2);
          }
          lazy[k] = 0;
      }
  }

  void add(ll a,ll b,ll x,ll k = 0,ll l = 0,ll r = -1){
      if(r < 0) r = N;
      eval(k,l,r);
      if(b <= l || r <= a) return;
      if(a <= l && r <= b){
          lazy[k] += (r-l) * x;
          eval(k,l,r);
      }else{
          add(a,b,x,k*2+1,l,(l+r)/2);
          add(a,b,x,k*2+2,(l+r)/2,r);
          data[k] = data[k*2+1] + data[k*2+2];
      }
  }
  
  T query(ll a,ll b,ll k = 0,ll l = 0,ll r = -1){
      if(r < 0) r = N;
      eval(k,l,r);
      if(b <= l || r <= a) return def;
      if(a <= l && r <= b){
          return data[k];
      }else{
          T c1 = query(a,b,k*2+1,l,(l+r)/2);
          T c2 = query(a,b,k*2+2,(l+r)/2,r);
          return operation(c1,c2);
      }
  }

  T operator[](ll i){
      return lazy[i+N-1];
  }

  T oper(ll i){
      return data[i+N-1];
  }

};



int main(){
    ll N;
    string S;
    ll Q;
    cin >> N >> S >> Q;
    SegmentTree<ll> SA(500010,0,f,g);
    SegmentTree<ll> SB(500010,0,f,g);
    SegmentTree<ll> SC(500010,0,f,g);
    SegmentTree<ll> SD(500010,0,f,g);
    SegmentTree<ll> SE(500010,0,f,g);
    SegmentTree<ll> SF(500010,0,f,g);
    SegmentTree<ll> SG(500010,0,f,g);
    SegmentTree<ll> SH(500010,0,f,g);
    SegmentTree<ll> SI(500010,0,f,g);
    SegmentTree<ll> SJ(500010,0,f,g);
    SegmentTree<ll> SK(500010,0,f,g);
    SegmentTree<ll> SL(500010,0,f,g);
    SegmentTree<ll> SM(500010,0,f,g);
    SegmentTree<ll> SN(500010,0,f,g);
    SegmentTree<ll> SO(500010,0,f,g);
    SegmentTree<ll> SP(500010,0,f,g);
    SegmentTree<ll> SQ(500010,0,f,g);
    SegmentTree<ll> SR(500010,0,f,g);
    SegmentTree<ll> SS(500010,0,f,g);
    SegmentTree<ll> ST(500010,0,f,g);
    SegmentTree<ll> SU(500010,0,f,g);
    SegmentTree<ll> SV(500010,0,f,g);
    SegmentTree<ll> SW(500010,0,f,g);
    SegmentTree<ll> SX(500010,0,f,g);
    SegmentTree<ll> SY(500010,0,f,g);
    SegmentTree<ll> SZ(500010,0,f,g);
    rep(i,N){
        if(S[i] == 'a') SA.add(i+1,N+1,1);
        if(S[i] == 'b') SB.add(i+1,N+1,1);
        if(S[i] == 'c') SC.add(i+1,N+1,1);
        if(S[i] == 'd') SD.add(i+1,N+1,1);
        if(S[i] == 'e') SE.add(i+1,N+1,1);
        if(S[i] == 'f') SF.add(i+1,N+1,1);
        if(S[i] == 'g') SG.add(i+1,N+1,1);
        if(S[i] == 'h') SH.add(i+1,N+1,1);
        if(S[i] == 'i') SI.add(i+1,N+1,1);
        if(S[i] == 'j') SJ.add(i+1,N+1,1);
        if(S[i] == 'k') SK.add(i+1,N+1,1);
        if(S[i] == 'l') SL.add(i+1,N+1,1);
        if(S[i] == 'm') SM.add(i+1,N+1,1);
        if(S[i] == 'n') SN.add(i+1,N+1,1);
        if(S[i] == 'o') SO.add(i+1,N+1,1);
        if(S[i] == 'p') SP.add(i+1,N+1,1);
        if(S[i] == 'q') SQ.add(i+1,N+1,1);
        if(S[i] == 'r') SR.add(i+1,N+1,1);
        if(S[i] == 's') SS.add(i+1,N+1,1);
        if(S[i] == 't') ST.add(i+1,N+1,1);
        if(S[i] == 'u') SU.add(i+1,N+1,1);
        if(S[i] == 'v') SV.add(i+1,N+1,1);
        if(S[i] == 'w') SW.add(i+1,N+1,1);
        if(S[i] == 'x') SX.add(i+1,N+1,1);
        if(S[i] == 'y') SY.add(i+1,N+1,1);
        if(S[i] == 'z') SZ.add(i+1,N+1,1);
    }
    rep(i,Q){
        ll t;
        cin >> t;
        if(t == 1){
            ll x;
            char c;
            cin >> x >> c;
            x--;
            if(S[x] == c) continue;
            if(S[x] == 'a') SA.add(x+1,N+1,-1);
            if(S[x] == 'b') SB.add(x+1,N+1,-1);
            if(S[x] == 'c') SC.add(x+1,N+1,-1);
            if(S[x] == 'd') SD.add(x+1,N+1,-1);
            if(S[x] == 'e') SE.add(x+1,N+1,-1);
            if(S[x] == 'f') SF.add(x+1,N+1,-1);
            if(S[x] == 'g') SG.add(x+1,N+1,-1);
            if(S[x] == 'h') SH.add(x+1,N+1,-1);
            if(S[x] == 'i') SI.add(x+1,N+1,-1);
            if(S[x] == 'j') SJ.add(x+1,N+1,-1);
            if(S[x] == 'k') SK.add(x+1,N+1,-1);
            if(S[x] == 'l') SL.add(x+1,N+1,-1);
            if(S[x] == 'm') SM.add(x+1,N+1,-1);
            if(S[x] == 'n') SN.add(x+1,N+1,-1);
            if(S[x] == 'o') SO.add(x+1,N+1,-1);
            if(S[x] == 'p') SP.add(x+1,N+1,-1);
            if(S[x] == 'q') SQ.add(x+1,N+1,-1);
            if(S[x] == 'r') SR.add(x+1,N+1,-1);
            if(S[x] == 's') SS.add(x+1,N+1,-1);
            if(S[x] == 't') ST.add(x+1,N+1,-1);
            if(S[x] == 'u') SU.add(x+1,N+1,-1);
            if(S[x] == 'v') SV.add(x+1,N+1,-1);
            if(S[x] == 'w') SW.add(x+1,N+1,-1);
            if(S[x] == 'x') SX.add(x+1,N+1,-1);
            if(S[x] == 'y') SY.add(x+1,N+1,-1);
            if(S[x] == 'z') SZ.add(x+1,N+1,-1);
            
            if(c == 'a') SA.add(x+1,N+1,1);
            if(c == 'b') SB.add(x+1,N+1,1);
            if(c == 'c') SC.add(x+1,N+1,1);
            if(c == 'd') SD.add(x+1,N+1,1);
            if(c == 'e') SE.add(x+1,N+1,1);
            if(c == 'f') SF.add(x+1,N+1,1);
            if(c == 'g') SG.add(x+1,N+1,1);
            if(c == 'h') SH.add(x+1,N+1,1);
            if(c == 'i') SI.add(x+1,N+1,1);
            if(c == 'j') SJ.add(x+1,N+1,1);
            if(c == 'k') SK.add(x+1,N+1,1);
            if(c == 'l') SL.add(x+1,N+1,1);
            if(c == 'm') SM.add(x+1,N+1,1);
            if(c == 'n') SN.add(x+1,N+1,1);
            if(c == 'o') SO.add(x+1,N+1,1);
            if(c == 'p') SP.add(x+1,N+1,1);
            if(c == 'q') SQ.add(x+1,N+1,1);
            if(c == 'r') SR.add(x+1,N+1,1);
            if(c == 's') SS.add(x+1,N+1,1);
            if(c == 't') ST.add(x+1,N+1,1);
            if(c == 'u') SU.add(x+1,N+1,1);
            if(c == 'v') SV.add(x+1,N+1,1);
            if(c == 'w') SW.add(x+1,N+1,1);
            if(c == 'x') SX.add(x+1,N+1,1);
            if(c == 'y') SY.add(x+1,N+1,1);
            if(c == 'z') SZ.add(x+1,N+1,1);
            S[x] = c;
        }else{
            ll l,r;
            cin >> l >> r;
            l--;
            ll cnt = 0;
            if(SA.query(r,r+1)-SA.query(l,l+1) > 0) cnt++;
            if(SB.query(r,r+1)-SB.query(l,l+1) > 0) cnt++;
            if(SC.query(r,r+1)-SC.query(l,l+1) > 0) cnt++;
            if(SD.query(r,r+1)-SD.query(l,l+1) > 0) cnt++;
            if(SE.query(r,r+1)-SE.query(l,l+1) > 0) cnt++;
            if(SF.query(r,r+1)-SF.query(l,l+1) > 0) cnt++;
            if(SG.query(r,r+1)-SG.query(l,l+1) > 0) cnt++;
            if(SH.query(r,r+1)-SH.query(l,l+1) > 0) cnt++;
            if(SI.query(r,r+1)-SI.query(l,l+1) > 0) cnt++;
            if(SJ.query(r,r+1)-SJ.query(l,l+1) > 0) cnt++;
            if(SK.query(r,r+1)-SK.query(l,l+1) > 0) cnt++;
            if(SL.query(r,r+1)-SL.query(l,l+1) > 0) cnt++;
            if(SM.query(r,r+1)-SM.query(l,l+1) > 0) cnt++;
            if(SN.query(r,r+1)-SN.query(l,l+1) > 0) cnt++;
            if(SO.query(r,r+1)-SO.query(l,l+1) > 0) cnt++;
            if(SP.query(r,r+1)-SP.query(l,l+1) > 0) cnt++;
            if(SQ.query(r,r+1)-SQ.query(l,l+1) > 0) cnt++;
            if(SR.query(r,r+1)-SR.query(l,l+1) > 0) cnt++;
            if(SS.query(r,r+1)-SS.query(l,l+1) > 0) cnt++;
            if(ST.query(r,r+1)-ST.query(l,l+1) > 0) cnt++;
            if(SU.query(r,r+1)-SU.query(l,l+1) > 0) cnt++;
            if(SV.query(r,r+1)-SV.query(l,l+1) > 0) cnt++;
            if(SW.query(r,r+1)-SW.query(l,l+1) > 0) cnt++;
            if(SX.query(r,r+1)-SX.query(l,l+1) > 0) cnt++;
            if(SY.query(r,r+1)-SY.query(l,l+1) > 0) cnt++;
            if(SZ.query(r,r+1)-SZ.query(l,l+1) > 0) cnt++;
            cout << cnt << endl;
        }
    }
}


Measured memory_bytes: 427140