#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(ll x) { return 63-__builtin_clzll(x); } // floor(log2(x))
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


template<typename T>
struct SegmentTree {
  int m, n; // m: size of original vector, n: size of segment tree
  vector<T> d;
  T idt = 0; // identity element
  T op(T &a, T &b) {
    return a | b;
  }

  SegmentTree(vector<T> v) : m(v.size()) {
    n = 1; while(n < m) n <<= 1;
    d.assign(2*n-1, idt);
    rep(i, m) d[i+n-1] = v[i];
    drep(i, n-1) d[i] = op(d[(i<<1)+1], d[(i<<1)+2]);
  }
  void add(int i, T val) {
    i += n-1, d[i] += val;
    while (i) i = (i-1)>>1, d[i] = op(d[(i<<1)+1], d[(i<<1)+2]);
  }
  void set(int i, T val) {
    i += n-1, d[i] = val;
    while (i) i = (i-1)>>1, d[i] = op(d[(i<<1)+1], d[(i<<1)+2]);
  }
  T op_range(int i, int j, int k=0, int l=0, int r=-1) {
    if (r < 0) r = n;
    if (j <= l || r <= i) return idt;
    if (i <= l && r <= j) return d[k];
    T vl = op_range(i, j, (k<<1)+1, l, (l+r)>>1);
    T vr = op_range(i, j, (k<<1)+2, (l+r)>>1, r);
    return op(vl, vr);
  }
  T operator[](const int i) { return d[n-1+i]; }
};


int main() {
  ll n; cin >> n;
  string s; cin >> s;

  V v(n);
  rep(i, n) {
    int x = s[i] - 'a';
    v[i] = (1<<x);
  }

  SegmentTree<int> st(v);

  int q; cin >> q;
  rep(_, q) {
    int t; cin >> t;
    if (t == 1) {
      int i; char c; cin >> i >> c;
      --i;
      int x = c - 'a';
      st.set(i, 1<<x);
    }
    else {
      int l, r; cin >> l >> r;
      --l;
      int ans = __builtin_popcount(st.op_range(l, r));
      cout << ans << '\n';
    }
  }

  return 0;
}


Measured memory_bytes: 11908