#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  string s;
  cin >> s;
  char x = 'a';
  int y;
  set<int> arr[26];
  for (int i = 0; i < s.length(); i++) {
    y = s[i] - x;
    arr[y].insert(i);
  }
  int q;
  cin >> q;
  int n, ans = 0;
  for (int i = 0; i < q; i++) {
    cin >> n;
    if (n == 1) {
      int pos;
      char c;
      cin >> pos >> c;
      y = s[pos - 1] - x;
      arr[y].erase(pos - 1);
      s[pos - 1] = c;
      y = c - x;
      arr[y].insert(pos - 1);
    }
    if (n == 2) {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      for (int i = 0; i < 26; i++) {
        auto it = arr[i].lower_bound(l);
        if (it == arr[i].end())
          continue;
        else if (*it <= r)
          ans++;
      }
      cout << ans << endl;
      ans = 0;
    }
  }
  return 0;
}
