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

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz *= 2;
    seg.assign(2 * sz, M1);//実装を楽にするため二倍のメモリを確保
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;//後のアクセスの為の実装上の工夫
  }

  void build() {
    //要素全部セットした後に呼ぶ
    // O(sz)
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    // k番目の要素をxに変更する
    // O(logN)
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    //区間[a,b)に二項演算した結果を返す
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }

  template< typename C >
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    //内部関数
    while(a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }


  template< typename C >
  int find_first(int a, const C &check) {
    // [a,x)がcheckを満たす最初の一要素xを返す
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, seg[a]);
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  template< typename C >
  int find_last(int b, const C &check) {
    // [x,b)がcheckを満たす最後の一要素を返す
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(seg[--b], R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};

unsigned int build_flag(char a){
  int b = a - 'a';
  uint ret = 1;
  ret <<= b; 
  return ret;
}
int count(uint a){
  int cnt =0;
  while(a!=0){
    cnt += a%2;
    a /=2;
  }
  return cnt;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    int N;
    string S;
    int Q;
    cin >> N;
    cin >> S ;
    cin >> Q;
    auto product =  [](int a, int b){ return a|b;};
    uint M1 = 0;
    SegmentTree<uint> st(N,product,M1);
    for (int i=0;i<N;i++){
      st.set(i,build_flag(S[i]));
    }
    st.build();
    for (int i=0;i<Q;i++){
      int query_type,pos,l,r;
      char c;
      scanf("%d",&query_type);
      if (query_type==1){
        scanf("%d %c",&pos,&c);
        st.update(pos-1,build_flag(c));
      }else{
        scanf("%d %d",&l,&r);
        int ret = count(st.query(l-1,r));
        printf("%d\n",ret);
      }


    }

    return 0;
}


Measured memory_bytes: 5124