#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 9;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  long long q;
  cin >> q;
  long long n = s.size();
  vector<set<long long> > alp(26);
  for (long long i = 0; i < n; ++i) alp[s[i] - 'a'].insert(i);
  while (q--) {
    long long type;
    cin >> type;
    if (type == 1) {
      long long ind;
      char c;
      cin >> ind >> c;
      --ind;
      alp[s[ind] - 'a'].erase(ind);
      s[ind] = c;
      alp[s[ind] - 'a'].insert(ind);
    } else {
      long long l, r;
      cin >> l >> r;
      --l, --r;
      long long ans = 0;
      for (long long i = (long long)(0); i < (long long)(26); ++i) {
        auto le = alp[i].upper_bound(l - 1);
        if (le != alp[i].end() && *le <= r) ++ans;
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
