#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int q;
  cin >> s >> q;
  set<int> ar[26];
  for (int i = 0; i < s.length(); i++) {
    ar[s[i] - 'a'].insert(i);
  }
  for (int o = 0; o < q; o++) {
    int is;
    cin >> is;
    if (is == 1) {
      int ind;
      char a;
      cin >> ind >> a;
      ar[s[ind - 1] - 'a'].erase(ind - 1);
      ar[a - 'a'].insert(ind - 1);
      s[ind - 1] = a;
    }
    if (is == 2) {
      int l, r;
      cin >> l >> r;
      int ans = 0;
      for (int i = 0; i < 26; i++) {
        auto up = ar[i].upper_bound(r - 1);
        if (up != ar[i].begin()) {
          up--;
          if (*up >= l - 1) {
            ans++;
          }
        }
      }
      cout << ans << '\n';
    }
  }
}
