#include <bits/stdc++.h>
using namespace std;
int getSum(vector<int> BITree[], int index, int n) {
  int sum = 0;
  index = index + 1;
  while (index > 0) {
    sum += BITree[n][index];
    index -= index & (-index);
  }
  return sum;
}
void updateBIT(vector<int> BITree[], int n, int index, int val, int num) {
  index = index + 1;
  while (index <= n) {
    BITree[num][index] += val;
    index += index & (-index);
  }
}
int main() {
  string str;
  cin >> str;
  int n = str.size();
  int q;
  cin >> q;
  int type;
  int pos;
  char ch, ch2;
  int num, num2;
  int l, r;
  vector<int> bit[26];
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < n + 1; j++) bit[i].push_back(0);
  }
  for (int i = 0; i < n; i++) {
    ch = str[i];
    num = int(ch) - 97;
    updateBIT(bit, n, i, 1, num);
  }
  while (q--) {
    cin >> type;
    if (type == 1) {
      cin >> pos >> ch;
      pos--;
      num = int(ch) - 97;
      ch2 = str[pos];
      str[pos] = ch;
      num2 = int(ch2) - 97;
      updateBIT(bit, n, pos, 1, num);
      updateBIT(bit, n, pos, -1, num2);
    } else {
      cin >> l >> r;
      l--, r--;
      int cnt = 0;
      for (int i = 0; i < 26; i++)
        if (getSum(bit, r, i) - getSum(bit, l - 1, i) > 0) cnt++;
      cout << cnt << "\n";
    }
  }
  return 0;
}
