#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.length();
  map<int, int> v[26];
  map<int, int>::iterator it;
  for (int i = 0; i < n; i++) {
    v[s[i] - 'a'][i] = 1;
  }
  int q;
  cin >> q;
  while (q--) {
    int a;
    cin >> a;
    if (a == 1) {
      int b;
      char c;
      cin >> b >> c;
      b--;
      it = v[s[b] - 'a'].find(b);
      v[s[b] - 'a'].erase(it);
      v[c - 'a'][b] = 1;
      s[b] = c;
    } else {
      int b, c;
      cin >> b >> c;
      b--;
      c--;
      int ans = 0;
      for (int i = 0; i < 26; i++) {
        if (v[i].find(b) != v[i].end())
          ans++;
        else {
          v[i][b] = 1;
          it = v[i].find(b);
          if (next(it) != v[i].end() && next(it)->first <= c) {
            ans++;
          }
          v[i].erase(it);
        }
      }
      cout << ans << endl;
    }
  }
}
