/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-01 19:48:32
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

template <class Monoid, class Function>
class SegmentTree {
 public:
  SegmentTree(const std::vector<Monoid>& data, Monoid identity_element,
              Function function)
      : identity_element_(identity_element), data_(data), function_(function) {
    Build();
  }

  void Update(size_t position, Monoid new_value) {
    position += n_;
    node_[position] = new_value;
    while (position > 0) {
      position >>= 1;
      node_[position] = function_(node_[2 * position], node_[2 * position + 1]);
    }
  }

  // return Query[left, right)
  Monoid Query(int left, int right) {
    Monoid vl = identity_element_, vr = identity_element_;
    for (left += n_, right += n_; left < right; left >>= 1, right >>= 1) {
      if (left & 1) vl = function_(vl, node_[left++]);
      if (right & 1) vr = function_(node_[--right], vr);
    }
    return function_(vl, vr);
  }

  Monoid operator[](size_t position) const { return node_[n_ + position]; }

 private:
  size_t n_;
  Monoid identity_element_;
  std::vector<Monoid> data_;
  std::vector<Monoid> node_;
  Function function_;

  void Build() {
    size_t SIZE = data_.size();
    n_ = 1;
    while (n_ < SIZE) {
      n_ <<= 1;
    }
    node_.assign(2 * n_, identity_element_);
    for (size_t i = 0; i < SIZE; ++i) {
      node_[i + n_] = data_[i];
    }
    for (size_t i = n_ - 1; i > 0; --i) {
      node_[i] = function_(node_[2 * i], node_[2 * i + 1]);
    }
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  string s; cin >> s;
  
  auto f = [](bitset<26> x, bitset<26> y) { return x | y; };
  SegmentTree<bitset<26>, decltype(f)> seg(vector<bitset<26>>(n, 0), 0, f);
  for (int i = 0; i < n; ++i) {
    seg.Update(i, seg[i].flip(s[i] - 'a'));
  }

  int q; cin >> q;
  for (int i = 0; i < q; ++i) {
    int op; cin >> op;
    if (op == 1) {
      int pos; char next; cin >> pos >> next; --pos;
      if (s[pos] == next) continue;
      char cur = s[pos];
      seg.Update(pos, seg[pos].flip(cur - 'a'));
      seg.Update(pos, seg[pos].flip(next - 'a'));
      s[pos] = next;
    } else {
      int l, r; cin >> l >> r; --l; --r;
      cout << seg.Query(l, r + 1).count() << '\n';
    }
  }

  return 0;
}

Measured memory_bytes: 16924