#include <bits/stdc++.h>
using namespace std;
int main() {
  map<char, set<int>> mp;
  string s;
  int n, x, pos, l, r, cnt = 0;
  char ch;
  cin >> s >> n;
  for (int i = 0; i < s.size(); i++) {
    mp[s[i]].insert(i + 1);
  }
  while (n--) {
    cin >> x;
    if (x == 1) {
      cin >> pos >> ch;
      mp[s[pos - 1]].erase(pos);
      mp[ch].insert(pos);
      s[pos - 1] = ch;
    } else {
      cin >> l >> r;
      cnt = 0;
      for (char A = 'a'; A <= 'z'; A++) {
        if (mp[A].lower_bound(l) != mp[A].upper_bound(r)) cnt++;
      }
      cout << cnt << '\n';
    }
  }
  return 0;
}
