#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 4;
const int X[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int Y[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int mod = 1e9 + 7;
const long long INF = 1e16;
const int inf = 1e9;
int n;
int a[N];
int f[27][N];
void upd(int j, int pos, int x = 1) {
  for (int i = pos; i < N; i = (i | (i + 1))) {
    f[j][i] += x;
  }
}
int get(int j, int pos) {
  int res = 0;
  for (int i = pos; i >= 0; i = (i & (i + 1)) - 1) {
    res += f[j][i];
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  ;
  string s;
  cin >> s;
  int q;
  cin >> q;
  n = s.size();
  for (int i = 0; i < n; ++i) {
    a[i] = (s[i] - 'a');
    upd(a[i], i);
  }
  while (q--) {
    int type, l, r;
    cin >> type >> l;
    if (type == 2) {
      cin >> r;
      --l;
      --r;
      int res = 0;
      for (int i = 0; i < 27; ++i) {
        res += min(1, get(i, r) - (get(i, l - 1)));
      }
      cout << res << "\n";
    } else {
      --l;
      char c;
      cin >> c;
      int u = c - 'a';
      upd(a[l], l, -1);
      a[l] = u;
      upd(a[l], l);
    }
  }
}
