#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &res) {
  bool flag = false;
  char ch;
  while (!isdigit(ch = getchar())) (ch == '-') && (flag = true);
  for (res = ch - '0'; isdigit(ch = getchar()); res = res * 10 + ch - '0')
    ;
  flag && (res = -res);
}
template <typename T>
void write(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const int maxn = 1e5 + 10;
const int M = 50010;
int n, m;
int qu_num, op_num;
int lst[maxn], col[maxn], blo[maxn], cnt[1000010], res[maxn];
char s[maxn];
struct query {
  int l, r, t, pos;
  bool operator<(const query &a) const {
    return blo[a.l] == blo[l]
               ? (blo[a.r] == blo[r] ? t < a.t : blo[r] < blo[a.r])
               : blo[l] < blo[a.l];
  }
} qu[maxn];
struct oper {
  int x, lst, now;
} op[maxn];
int main() {
  scanf("%s", s);
  int len = strlen(s);
  n = len;
  int q = pow(n, 0.666666);
  for (int i = 1; i <= n; i++)
    col[i] = s[i - 1] - 'a' + 1, blo[i] = (i - 1) / q + 1, lst[i] = col[i];
  int x, y;
  read(m);
  for (int i = 1; i <= m; i++) {
    int oper;
    read(oper);
    read(x);
    if (oper == 2) {
      read(y);
      qu[++qu_num].l = x, qu[qu_num].r = y,
      qu[qu[qu_num].pos = qu_num].t = op_num;
    } else {
      char ch[3];
      cin >> ch;
      y = ch[0] - 'a' + 1;
      op[++op_num].x = x, op[op_num].lst = lst[x], op[op_num].now = y,
      lst[x] = y;
    }
  }
  sort(qu + 1, qu + 1 + qu_num);
  int l = 0, r = 0, t = 0, ans = 0;
  for (int i = 1; i <= qu_num; i++) {
    while (t < qu[i].t) {
      t++;
      if (l <= op[t].x && op[t].x <= r) {
        if (!--cnt[col[op[t].x]]) ans--;
        if (!cnt[op[t].now]++) ans++;
      }
      col[op[t].x] = op[t].now;
    }
    while (t > qu[i].t) {
      if (l <= op[t].x && op[t].x <= r) {
        if (!--cnt[col[op[t].x]]) ans--;
        if (!cnt[op[t].lst]++) ans++;
      }
      col[op[t].x] = op[t].lst;
      t--;
    }
    while (r < qu[i].r)
      if (!cnt[col[++r]]++) ans++;
    while (l > qu[i].l)
      if (!cnt[col[--l]]++) ans++;
    while (r > qu[i].r)
      if (!--cnt[col[r--]]) ans--;
    while (l < qu[i].l)
      if (!--cnt[col[l++]]) ans--;
    res[qu[i].pos] = ans;
  }
  for (int i = 1; i <= qu_num; i++) write(res[i]), putchar('\n');
  return 0;
}
