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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

template<class T,class F>
struct segtree{
  int n;
  T e;
  F f;
  std::vector<T> dat;

  segtree(){}
  segtree(int sz,T _e,F _f):e(_e),f(_f){
    n = 1;
    while(n<=sz)n<<=1;
    dat.resize(2*n,e);
  }
  segtree(std::vector<T> const& v,T _e,F _f):e(_e),f(_f){
    build(v);
  }
  void build(std::vector<T> const& v){
    n = 1;
    int sz = v.size();
    while(n<=sz)n<<=1;
    dat.resize(2*n,e);
    for(int i=0;i<sz;++i){
      dat[i+n] = v[i];
    }
    for(int i=n-1;i>0;--i){
      dat[i] = f(dat[i<<1],dat[i<<1|1]);
    }
  }
  void set(int p,T v){
    for(dat[p+=n]=v;p>1;p>>=1){
      dat[p>>1] = f(dat[p],dat[p^1]);
    }
  }
  T query(int l,int r){
    T res = e;
    for(l+=n,r+=n;l<r;l>>=1,r>>=1){
      if(l&1){
        res = f(res,dat[l]);
        l++;
      }
      if(r&1){
        r--;
        res = f(res,dat[r]);
      }
    }
    return res;
  }
  T operator[](int k){
    return query(k,k+1);
  }
};

int main(){

  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  string s;
  cin>>n>>s;

  using pis = pair<int,set<char>>;
  auto merge = [](auto& a,auto& b){
    pis res;
    set_union(a.second.begin(),a.second.end(),b.second.begin(),b.second.end(),inserter(res.second,end(res.second)));
    res.first = res.second.size();
    return res;
  };
  pis id;
  id.first = 0;
  vector<pis> a(n);
  rep(i,n){
    a[i].first = 1;
    a[i].second.emplace(s[i]);
  }
  segtree<pis,decltype(merge)> seg(a,id,merge);

  /*
  rep(i,n){
    cout<<i<<" : ";
    for(auto x:seg[i].second){
      cout<<x<<" ";
    }
    cout<<endl;
  }
  */

  int q;
  cin>>q;
  while(q--){
    int com;
    cin>>com;
    if(com==1){
      int i;
      char c;
      cin>>i>>c;
      i--;
      pis t;
      t.first = 1;
      t.second.emplace(c);
      seg.set(i,t);
    }else{
      int l,r;
      cin>>l>>r;
      l--;r--;
      pis res = seg.query(l,r+1);
      cout<<res.first<<"\n";
    }
    /*
    rep(i,n){
      cout<<i<<" : ";
      for(auto x:seg[i].second){
        cout<<x<<" ";
      }
      cout<<endl;
    }
    */
  }
  cout<<endl;

}

Measured memory_bytes: 247708