#include <bits/stdc++.h>
using namespace std;
long long tree[30][100005 * 4];
void reset() {
  for (long long i = 0; i < 30; i++) {
    for (long long j = 0; j < 4 * 100005; j++) {
      tree[i][j] = 0;
    }
  }
}
string s;
long long q, l, r, t, n;
void update(long long nd, long long b, long long e, long long i, long long ch,
            long long val) {
  if (b > i or i > e)
    return;
  else if (b >= i && e <= i) {
    tree[ch][nd] = val;
    return;
  }
  long long lf = 2 * nd;
  long long rt = lf + 1;
  long long mid = (b + e) / 2;
  update(lf, b, mid, i, ch, val);
  update(rt, mid + 1, e, i, ch, val);
  tree[ch][nd] = tree[ch][lf] + tree[ch][rt];
}
long long query(long long nd, long long b, long long e, long long i,
                long long j, long long ch) {
  if (b > j or e < i)
    return 0;
  else if (b >= i && e <= j)
    return tree[ch][nd];
  long long lf = 2 * nd;
  long long rt = lf + 1;
  long long mid = (b + e) / 2;
  long long q1 = query(lf, b, mid, i, j, ch);
  long long q2 = query(rt, mid + 1, e, i, j, ch);
  return q1 + q2;
}
int main() {
  reset();
  cin >> s;
  n = s.size();
  s = '*' + s;
  cin >> q;
  for (long long i = 1; i <= n; i++) {
    long long ok = s[i] - 'a';
    update(1, 1, n, i, ok, 1);
  }
  for (long long i = 0; i < q; i++) {
    scanf("%lld", &t);
    char ch1;
    if (t == 1) {
      scanf("%lld %c", &l, &ch1);
      long long x = s[l] - 'a';
      long long y = ch1 - 'a';
      update(1, 1, n, l, x, 0);
      s[l] = ch1;
      update(1, 1, n, l, y, 1);
    } else {
      scanf("%lld %lld", &l, &r);
      long long cnt = 0;
      for (long long j = 0; j < 26; j++) {
        long long flag = 0;
        flag = query(1, 1, n, l, r, j);
        if (flag >= 1) {
          cnt++;
        }
      }
      printf("%lld\n", cnt);
    }
  }
  return 0;
}
