#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;
set<int> pos[26];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); ++i) {
    pos[s[i] - 'a'].insert(i);
  }
  int q;
  cin >> q;
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int p;
      char c;
      cin >> p >> c;
      --p;
      pos[s[p] - 'a'].erase(p);
      s[p] = c;
      pos[s[p] - 'a'].insert(p);
    } else {
      int l, r;
      cin >> l >> r;
      --l;
      --r;
      int ans = 0;
      for (int i = 0; i < 26; ++i) {
        auto it = pos[i].lower_bound(l);
        if (it != pos[i].end() and *it <= r) ++ans;
      }
      cout << ans << '\n';
    }
  }
}
