#include <bits/stdc++.h>
using namespace std;
int query(vector<int>& bit, int ind) {
  int sm = 0;
  for (; ind; ind -= ind & -ind) {
    sm += bit[ind];
  }
  return sm;
}
void update(vector<int>& bit, int ind, int delta) {
  for (; ind < bit.size(); ind += ind & -ind) {
    bit[ind] += delta;
  }
}
int main() {
  string s;
  cin >> s;
  vector<vector<int>> bits(26, vector<int>(s.size() + 1));
  for (int i = 0; i < s.size(); ++i) {
    update(bits[s[i] - 'a'], i + 1, 1);
  }
  int q;
  cin >> q;
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int pos;
      char newChar;
      cin >> pos >> newChar;
      int oldChar = s[pos - 1];
      update(bits[oldChar - 'a'], pos, -1);
      update(bits[newChar - 'a'], pos, 1);
      s[pos - 1] = newChar;
    } else {
      int l, r;
      cin >> l >> r;
      int sm = 0;
      for (int i = 0; i < 26; ++i) {
        sm += query(bits[i], r) - query(bits[i], l - 1) > 0;
      }
      cout << sm << endl;
    }
  }
  return 0;
}
