#include <bits/stdc++.h>
using namespace std;
void build(string &s, vector<vector<int>> &segtree, int i, int l, int r,
           int id) {
  if (l == r) {
    if (s[l] - 'a' == i)
      segtree[i][id] = 1;
    else
      segtree[i][id] = 0;
    return;
  }
  int mid = (l + r) / 2;
  build(s, segtree, i, l, mid, 2 * id + 1);
  build(s, segtree, i, mid + 1, r, 2 * id + 2);
  segtree[i][id] = max(segtree[i][id * 2 + 1], segtree[i][id * 2 + 2]);
}
int get_max(vector<vector<int>> &segtree, int i, int l, int r, int f, int t,
            int id) {
  if (f <= l && t >= r) return segtree[i][id];
  if (f > r || t < l) return -1e9;
  int mid = (l + r) / 2;
  return max(get_max(segtree, i, l, mid, f, t, 2 * id + 1),
             get_max(segtree, i, mid + 1, r, f, t, 2 * id + 2));
}
void upd(vector<vector<int>> &segtree, int i, string &s, int l, int r, int id,
         int pos, char val) {
  int tmp = s[pos] - 'a';
  if (pos < l || r < pos) return;
  if (l == r) {
    segtree[tmp][id] = 0;
    s[pos] = val;
    segtree[i][id] = 1;
    return;
  }
  int mid = (l + r) / 2;
  if (pos <= mid)
    upd(segtree, i, s, l, mid, 2 * id + 1, pos, val);
  else
    upd(segtree, i, s, mid + 1, r, 2 * id + 2, pos, val);
  segtree[i][id] = max(segtree[i][2 * id + 1], segtree[i][2 * id + 2]);
  segtree[tmp][id] = max(segtree[tmp][2 * id + 1], segtree[tmp][2 * id + 2]);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  int q, x;
  cin >> s >> q;
  int h = (int)ceil(log2(s.size()));
  int sizetree = 2 * (int)pow(2, h) - 1;
  vector<vector<int>> segtree(26, vector<int>(sizetree));
  for (int i = 0; i < 26; i++) build(s, segtree, i, 0, s.size() - 1, 0);
  while (q--) {
    cin >> x;
    switch (x) {
      case 1: {
        char c;
        int pos, i;
        cin >> pos >> c;
        i = (int)c - 'a';
        --pos;
        upd(segtree, i, s, 0, s.size() - 1, 0, pos, c);
        break;
      }
      case 2: {
        int l, r, cnt = 0;
        cin >> l >> r;
        --l;
        --r;
        for (int i = 0; i < 26; i++)
          if (get_max(segtree, i, 0, s.size() - 1, l, r, 0) == 1) ++cnt;
        cout << cnt << endl;
        break;
      }
    }
  }
}
