#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, x, y, k, q, ans = 0;
  string s;
  char c;
  cin >> s >> q;
  int n = s.length();
  vector<set<int> > v(26);
  for (i = 0; i < n; i++) v[s[i] - 'a'].insert(i);
  while (q--) {
    cin >> x;
    if (x == 1) {
      cin >> y >> c;
      y--;
      v[s[y] - 'a'].erase(y);
      s[y] = c;
      v[s[y] - 'a'].insert(y);
    } else {
      cin >> x >> y;
      x--;
      y--;
      int sum = 0;
      for (i = 0; i < 26; i++) {
        auto it = v[i].lower_bound(x);
        if (it != v[i].end() && *it <= y) sum++;
      }
      cout << sum << endl;
    }
  }
  return 0;
}
