#include <bits/stdc++.h>
using namespace std;
int arr[200010], last[200010];
int tree[30][200010 * 4];
void make_tree(int no, int node, int b, int e) {
  if (b == e) {
    tree[no][node] = arr[b];
    return;
  }
  int Left = node * 2;
  int Right = node * 2 + 1;
  int mid = (b + e) / 2;
  make_tree(no, Left, b, mid);
  make_tree(no, Right, mid + 1, e);
  tree[no][node] = max(tree[no][Left], tree[no][Right]);
}
int query(int no, int node, int b, int e, int i, int j) {
  if (i > e || j < b) return 0;
  if (b >= i && e <= j) return tree[no][node];
  int Left = node * 2;
  int Right = node * 2 + 1;
  int mid = (b + e) / 2;
  int p1 = query(no, Left, b, mid, i, j);
  int p2 = query(no, Right, mid + 1, e, i, j);
  return max(p1, p2);
}
void update(int no, int node, int b, int e, int i, int newvalue) {
  if (i > e || i < b) return;
  if (b >= i && e <= i) {
    tree[no][node] = newvalue;
    return;
  }
  int Left = node * 2;
  int Right = node * 2 + 1;
  int mid = (b + e) / 2;
  update(no, Left, b, mid, i, newvalue);
  update(no, Right, mid + 1, e, i, newvalue);
  tree[no][node] = tree[no][Left] + tree[no][Right];
}
int main() {
  int l, r, q, pos, i, j, n, x, res, ans, ck, ck1;
  string s;
  char ch;
  cin >> s;
  n = s.size();
  for (i = 1; i <= 26; i++) {
    for (j = 1; j <= n; j++) {
      if (s[j - 1] - 'a' + 1 == i) {
        arr[j] = i;
        last[j] = i;
      } else
        arr[j] = 0;
    }
    make_tree(i, 1, 1, n);
  }
  cin >> q;
  while (q--) {
    cin >> x;
    if (x == 1) {
      cin >> pos;
      cin >> ch;
      ck = last[pos];
      update(ck, 1, 1, n, pos, 0);
      ck1 = ch - 'a' + 1;
      update(ck1, 1, 1, n, pos, ck1);
      last[pos] = ck1;
    }
    if (x == 2) {
      ans = 0;
      cin >> l >> r;
      for (i = 1; i <= 26; i++) {
        res = query(i, 1, 1, n, l, r);
        if (res > 0) ans++;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
