#include <bits/stdc++.h>
using namespace std;
long long int bin(long long int a, long long int b) {
  if (b == 0) return 1;
  if (b & 1) return (a * bin((a * a) % 1000000007, b / 2)) % 1000000007;
  return (1 * bin((a * a) % 1000000007, b / 2)) % 1000000007;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string str;
  cin >> str;
  vector<set<int> > s(26);
  int n = str.size();
  for (int i = 0; i < n; i++) {
    int k = str[i] - 'a';
    s[k].insert(i + 1);
  }
  str = " " + str;
  int q;
  cin >> q;
  while (q--) {
    int temp;
    cin >> temp;
    if (temp == 1) {
      int pos;
      char ch;
      cin >> pos >> ch;
      char k = str[pos];
      int k1 = k - 'a';
      s[k1].erase(pos);
      str[pos] = ch;
      k1 = ch - 'a';
      s[k1].insert(pos);
    } else {
      int l, r;
      cin >> l >> r;
      int cnt = 0;
      for (int i = 0; i < 26; i++) {
        set<int>::iterator it;
        it = s[i].lower_bound(l);
        int k1 = *it;
        if (k1 >= l && k1 <= r) {
          cnt++;
        }
      }
      cout << cnt << endl;
    }
  }
}
