#include <bits/stdc++.h>
using namespace std;
long double err = 0.000000001;
int ar[26][100005], tree[26][100005 * 4];
void SegmentTree(int ind, int node, int lo, int hi) {
  if (lo == hi) {
    tree[ind][node] = ar[ind][lo];
    return;
  }
  int mid = (lo + hi) / 2;
  SegmentTree(ind, node * 2, lo, mid);
  SegmentTree(ind, node * 2 + 1, mid + 1, hi);
  tree[ind][node] = tree[ind][node * 2] + tree[ind][node * 2 + 1];
}
int Query(int ind, int node, int lo, int hi, int i, int j) {
  if (lo >= i && hi <= j) return tree[ind][node];
  if (hi < i || lo > j) return 0;
  int mid = (lo + hi) / 2;
  return Query(ind, node * 2, lo, mid, i, j) +
         Query(ind, node * 2 + 1, mid + 1, hi, i, j);
}
void Update(int ind, int node, int lo, int hi, int i, int val) {
  if (lo == hi) {
    tree[ind][node] = val;
    return;
  }
  int mid = (hi + lo) / 2;
  if (i <= mid)
    Update(ind, node * 2, lo, mid, i, val);
  else
    Update(ind, node * 2 + 1, mid + 1, hi, i, val);
  tree[ind][node] = tree[ind][node * 2] + tree[ind][node * 2 + 1];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  int ss = (int)s.size() + 1;
  for (int i = 0; i < ss - 1; i++) {
    ar[s[i] - 'a'][i + 1] = 1;
  }
  for (int i = 0; i < 26; i++) {
    SegmentTree(i, 1, 1, ss);
  }
  int q;
  cin >> q;
  while (q--) {
    int w;
    cin >> w;
    if (w == 1) {
      int in;
      char c;
      cin >> in >> c;
      char nn = s[in - 1];
      Update((int)(nn - 'a'), 1, 1, ss, in, 0);
      s[in - 1] = c;
      Update((int)(c - 'a'), 1, 1, ss, in, 1);
    } else {
      int l, r;
      cin >> l >> r;
      int ans = 0;
      for (int i = 0; i < 26; i++) {
        int x = Query(i, 1, 1, ss, l, r);
        if (x) ans++;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
