#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string str;
  cin >> str;
  int t;
  cin >> t;
  int type, pos, l, r;
  char c;
  set<int> s[26];
  for (int i = 0; i < str.length(); i++) s[str[i] - 'a'].insert(i + 1);
  while (t--) {
    cin >> type;
    if (type == 1) {
      cin >> pos >> c;
      s[str[pos - 1] - 'a'].erase(pos);
      s[c - 'a'].insert(pos);
      str[pos - 1] = c;
    } else {
      cin >> l >> r;
      int count = 0;
      for (int i = 0; i < 26; i++)
        if (s[i].lower_bound(l) != s[i].upper_bound(r)) count++;
      cout << count << endl;
    }
  }
  return 0;
}
