#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  set<int> pos[26];
  for (int i = 0; i < s.length(); i++) {
    pos[s[i] - 'a'].insert(i);
  }
  for (int i = 0; i < 26; i++) pos[i].insert(1 << 30);
  int q;
  cin >> q;
  while (q-- > 0) {
    int a;
    cin >> a;
    if (a == 1) {
      int b;
      char c;
      cin >> b >> c;
      b--;
      pos[s[b] - 'a'].erase(b);
      s[b] = c;
      pos[s[b] - 'a'].insert(b);
    } else if (a == 2) {
      int b, c;
      cin >> b >> c;
      b--, c--;
      int cnt = 0;
      for (int i = 0; i < 26; i++) {
        cnt += (!pos[i].empty() && *(pos[i].lower_bound(b)) <= c);
      }
      cout << cnt << endl;
    }
  }
  return 0;
}
