#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  int n = s.length();
  vector<set<int>> rem(26);
  for (int i = 0; i < n; i++) {
    rem[s[i] - 'a'].insert(i);
  }
  int tt;
  cin >> tt;
  while (tt--) {
    int ch;
    cin >> ch;
    if (ch == 1) {
      int pos;
      char c;
      cin >> pos >> c;
      --pos;
      rem[s[pos] - 'a'].erase(pos);
      s[pos] = c;
      rem[c - 'a'].insert(pos);
    } else {
      int l, r;
      cin >> l >> r;
      int ans = 0;
      --l;
      --r;
      for (int i = 0; i < 26; i++) {
        auto it = rem[i].lower_bound(l);
        if (it != rem[i].end() && *it <= r) {
          ans++;
        }
      }
      cout << ans << "\n";
    }
  }
}
int main() {
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}
