#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  str = " " + str;
  set<long long int> s[26];
  for (long long int i = 1; i < str.size(); i++) s[str[i] - 'a'].insert(i);
  long long int t;
  cin >> t;
  while (t--) {
    long long int type;
    cin >> type;
    if (type == 1) {
      long long int x;
      char z;
      cin >> x >> z;
      s[str[x] - 'a'].erase(x);
      s[z - 'a'].insert(x);
      str[x] = z;
    }
    if (type == 2) {
      long long int m, n;
      cin >> m >> n;
      long long int ans = 0;
      for (long long int i = 0; i < 26; i++) {
        auto it = s[i].lower_bound(m);
        if (it != s[i].end() && *it <= n) {
          ans++;
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}
