#include <bits/stdc++.h>
using namespace std;
set<int> a[30];
string s;
int main() {
  ios::sync_with_stdio(false);
  int q;
  while (cin >> s) {
    for (int i = 0; i < 30; i++) a[i].clear();
    for (int i = 0; i < s.size(); i++) {
      a[s[i] - 'a'].insert(i);
    }
    cin >> q;
    int f;
    int num, l, r;
    char ch;
    while (q--) {
      cin >> f;
      if (f == 1) {
        cin >> num >> ch;
        a[s[num - 1] - 'a'].erase(num - 1);
        a[ch - 'a'].insert(num - 1);
        s[num - 1] = ch;
      } else {
        cin >> l >> r;
        int ans = 0;
        for (int i = 0; i < 26; i++) {
          set<int>::iterator k = a[i].lower_bound(l - 1);
          if (k != a[i].end() && *k < r) ans++;
        }
        cout << ans << endl;
      }
    }
  }
  return 0;
}
