#include <bits/stdc++.h>
using namespace std;
int q, test_var_xg, x, z, k, zxd, gg_easy, test_kk;
char str[112345];
const int neutral = 0;
class SegmentTree {
  vector<int> a;
  int n;

 public:
  SegmentTree(int* st, int* en) {
    int sz = int(en - st);
    for (n = 1; n < sz; n <<= 1)
      ;
    a.assign(n << 1, neutral);
    for (int i = 0; i < sz; i++) a[i + n] = st[i] + neutral;
    for (int i = n + sz - 1; i > 1; i--) a[i >> 1] = ((a[i >> 1]) + (a[i]));
  }
  void update(int i, int x) {
    a[i += n] = x + neutral;
    for (i >>= 1; i; i >>= 1) a[i] = ((a[i << 1]) + (a[1 + (i << 1)]));
  }
  int query(int l, int r) {
    int ans = neutral;
    for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
      if (l & 1) ans = ((ans) + (a[l++]));
      if (r & 1) ans = ((ans) + (a[--r]));
    }
    return ans;
  }
};
int main() {
  scanf("%s\n", str);
  int qtd[112345];
  vector<SegmentTree> seg;
  for (int i = 0; i <= ('z' - 'a'); i++) {
    memset(qtd, 0, sizeof(qtd));
    for (int j = 0; str[j]; j++) {
      qtd[j] = (str[j] - 'a') == i;
    }
    seg.push_back(SegmentTree(qtd, qtd + 112345 - 1));
  }
  cin >> q;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int pos;
      char newChar;
      cin >> pos >> newChar;
      seg[str[pos - 1] - 'a'].update(pos - 1, 0);
      seg[newChar - 'a'].update(pos - 1, 1);
      str[pos - 1] = newChar;
    } else {
      int l, r;
      cin >> l >> r;
      int ans = 0;
      for (int i = 0; i <= ('z' - 'a'); i++) {
        if (seg[i].query(l - 1, r - 1)) ans++;
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
