#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  long long int n = ((long long int)(s).size());
  long long int q;
  cin >> q;
  vector<long long int> ress;
  set<long long int> st[26];
  for (long long int i = 0; i < ((long long int)(n)); i++) {
    st[s[i] - 'a'].insert(i);
  }
  for (long long int i = 0; i < ((long long int)(q)); i++) {
    long long int typ;
    cin >> typ;
    if (typ == 1) {
      long long int pos;
      char upd;
      cin >> pos >> upd;
      pos--;
      st[s[pos] - 'a'].erase(pos);
      st[upd - 'a'].insert(pos);
      s[pos] = upd;
    } else {
      long long int l, r;
      cin >> l >> r;
      l--;
      r--;
      long long int res = 0;
      for (long long int j = 0; j < ((long long int)(26)); j++) {
        auto it = st[j].lower_bound(l);
        if (it != st[j].end() && *it <= r) {
          ++res;
        }
      }
      ress.push_back(res);
    }
  }
  for (auto res : ress) {
    printf("%I64d\n", res);
  }
  return 0;
}
