#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int n = 100000;
struct segtree {
  int tree[N * 4];
  void update(int at, int L, int R, int indx, int val) {
    if (L == R) {
      tree[at] += val;
      if (tree[at] > 1) tree[at] = 1;
      return;
    }
    int mid = (L + R) >> 1;
    if (indx <= mid)
      update(at * 2, L, mid, indx, val);
    else
      update(at * 2 + 1, mid + 1, R, indx, val);
    tree[at] = tree[at * 2] | tree[at * 2 + 1];
  }
  int get(int at, int L, int R, int l, int r) {
    if (l <= L and R <= r) return min(1, tree[at]);
    if (L > r or R < l) return 0;
    int mid = (L + R) >> 1;
    return get(at * 2, L, mid, l, r) | get(at * 2 + 1, mid + 1, R, l, r);
  }
} tre[27];
int main() {
  string s;
  cin >> s;
  for (int i = 0; i < (int)s.size(); i++) {
    tre[s[i] - 'a'].update(1, 1, n, i + 1, 1);
  }
  int q, type;
  cin >> q;
  while (q--) {
    cin >> type;
    int pos, l, r;
    char c;
    if (type == 1) {
      cin >> pos >> c;
      char cs = s[pos - 1];
      tre[cs - 'a'].update(1, 1, n, pos, -1);
      s[pos - 1] = c;
      tre[c - 'a'].update(1, 1, n, pos, 1);
    } else {
      cin >> l >> r;
      int ans = 0;
      for (int i = 0; i < 26; i++) {
        ans += tre[i].get(1, 1, n, l, r);
      }
      cout << ans << endl;
    }
  }
  return 0;
}
