#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  set<int> a[26];
  for (int i = 0; i < s.size(); i++) a[s[i] - 'a'].insert(i + 1);
  int q, t, x, y, cnt;
  cin >> q;
  char ch;
  while (q--) {
    cin >> t;
    if (t == 2) {
      cin >> x >> y;
      cnt = 0;
      for (int i = 0; i < 26; i++) {
        auto it = a[i].lower_bound(x);
        if (it != a[i].end() && *it <= y) cnt++;
      }
      cout << cnt << "\n";
    } else {
      cin >> x >> ch;
      if (s[x - 1] != ch) {
        a[s[x - 1] - 'a'].erase(x);
        a[ch - 'a'].insert(x);
        s[x - 1] = ch;
      }
    }
  }
  return;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
