#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  vector<set<int> > v(26);
  for (int i = 0; i < s.size(); i++) v[s[i] - 'a'].insert(i);
  int q = 0, op = 0;
  cin >> q;
  while (q--) {
    cin >> op;
    if (op == 1) {
      int pos = 0;
      char x;
      cin >> pos >> x;
      v[s[pos - 1] - 'a'].erase(pos - 1);
      s[pos - 1] = x;
      v[s[pos - 1] - 'a'].insert(pos - 1);
    } else {
      int l = 0, r = 0, ans = 0;
      cin >> l >> r;
      for (int i = 0; i < 26; i++) {
        auto it = v[i].lower_bound(l - 1);
        if (it != v[i].end() && *it <= r - 1) ans++;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
