#include <bits/stdc++.h>
using namespace std;
string S;
int Q;
int main() {
  cin >> S;
  cin >> Q;
  vector<set<int>> v(30);
  for (int i = 0; i < S.size(); ++i) {
    v[S[i] - 'a'].insert(i);
  }
  while (Q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int ind;
      char c;
      cin >> ind >> c;
      --ind;
      v[S[ind] - 'a'].erase(ind);
      S[ind] = c;
      v[c - 'a'].insert(ind);
    } else {
      int l, r;
      cin >> l >> r;
      --l, --r;
      int cnt = 0;
      for (int i = 0; i < 30; ++i) {
        auto m = v[i].lower_bound(l);
        if (m != v[i].end() && *m <= r) ++cnt;
      }
      cout << cnt << endl;
    }
  }
  return 0;
}
