#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;
set<int> all[26];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string ss;
  cin >> ss;
  vector<char> s(ss.size());
  for (int i = 0; i < ss.size(); i++) s[i] = ss[i];
  for (int i = 0; i < s.size(); i++) all[s[i] - 'a'].insert(i);
  int q, t, l, r;
  cin >> q;
  char ch;
  while (q--) {
    cin >> t >> l;
    if (t == 2) {
      cin >> r;
      l--;
      r--;
      int res = 0;
      for (int i = 0; i < 26; i++) {
        auto it = all[i].lower_bound(l);
        if (it == all[i].end() || *it > r) continue;
        res++;
      }
      cout << res << endl;
    } else {
      l--;
      cin >> ch;
      all[s[l] - 'a'].erase(l);
      all[ch - 'a'].insert(l);
      s[l] = ch;
    }
  }
  return 0;
}
