#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;

template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pa) {
  return os << "(" << pa.first << ", " << pa.second << ")";
}

template<typename Tuple, size_t N>
struct TuplePrinter {
  static void print(const Tuple &t) {
    TuplePrinter<Tuple, N-1>::print(t);
    cout << ", " << get<N-1>(t);
  }
};

template<typename Tuple>
struct TuplePrinter<Tuple, 1> {
  static void print(const Tuple &t) {
    cout << get<0>(t);
  }
};

template<typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &tup) {
  os << "(";
  TuplePrinter<decltype(tup), sizeof...(T)>::print(tup);
  return os << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }
#define dump(...) cout<<#__VA_ARGS__<<": [L_"<<__LINE__<<"]"<<'\n'; print(__VA_ARGS__);cout<<'\n';

template<class T, class U>inline bool chmax(T &a, const U &b) { if(a<b){ a=b; return 1; } return 0; }
template<class T, class U>inline bool chmin(T &a, const U &b) { if(b<a){ a=b; return 1; } return 0; }

/**
 * @brief BinaryIndexedTree
 * @note add|sum : O(logN)
 */
template<typename T>
struct BinaryIndexedTree {
public:
  vector<T> node;
  BinaryIndexedTree(int n_) : node() { node.resize(n_, 0); }
  void add(int k, T x) {
    for (int j = k + 1; j <= (int)node.size(); j += j & -j) node[j-1] += x;
  }
  T sum(int k) { // [0, k)
    T acc = 0;
    for (int j = k; j > 0; j -= j & -j) acc += node[j-1];
    return acc;
  }
};

int main() {
  int n; cin>>n;
  vector<char> s(n); rep(i, n) cin>>s[i];
  int q; cin>>q;

  vector<BinaryIndexedTree<int>> bit(27, BinaryIndexedTree<int>(n));
  {
    int t = s[0] - 'a';
    bit[t].add(0, 1);
  }
  REP(i, 1, n) {
    int t = s[i] - 'a';
    rep(j, 26) {
      bit[j].add(i, (t == j));
    }
  }

  rep(i, q) {
    int m; cin>>m;
    if (m == 1) {
      int l; cin>>l; --l;
      char c; cin>>c;
      int pre = s[l] - 'a';
      int aft = c - 'a';
      s[l] = c;
      bit[pre].add(l, -1);
      bit[aft].add(l, 1);
    } else {
      int l, r; cin>>l>>r;
      int ans = 0;
      rep(j, 26) {
        int x = bit[j].sum(r) - bit[j].sum(l-1);
        ans += (x >= 1);
      } 
      print(ans);
    }
  }

  return 0;
}

Measured memory_bytes: 55644