#include <bits/stdc++.h>
using namespace std;
int N;
char s[500010];
int c[30][500010];
int then(int x) { return x & -x; }
void in(int o, int x, int k) {
  while (x <= N) {
    c[o][x] += k;
    x += then(x);
  }
}
int out(int o, int x) {
  int re = 0;
  while (x > 0) {
    re += c[o][x];
    x -= then(x);
  }
  return re;
}
int main() {
  int Q;
  scanf("%s%d", s + 1, &Q);
  N = strlen(s + 1);
  for (int i = 1; i <= N; i++) in(s[i] - 'a', i, 1);
  for (int i = 1; i <= Q; i++) {
    int o;
    scanf("%d", &o);
    if (o == 1) {
      int k;
      char m;
      scanf("%d %c", &k, &m);
      in(s[k] - 'a', k, -1);
      in(m - 'a', k, 1);
      s[k] = m;
    } else {
      int x, y;
      scanf("%d%d", &x, &y);
      int give = 0;
      for (int i = 0; i <= 25; i++)
        if (out(i, y) - out(i, x - 1)) give++;
      printf("%d\n", give);
    }
  }
  return 0;
}
