#include <bits/stdc++.h>
using namespace std;
int q, num, pos, l, r;
char c;
string s;
bitset<26> t[400000 + 10];
void build(int v, int vl, int vr) {
  if (vl == vr) {
    t[v][s[vl] - 'a'] = 1;
  } else {
    int vm = (vl + vr) / 2;
    build(2 * v, vl, vm);
    build(2 * v + 1, vm + 1, vr);
    t[v] = t[2 * v] | t[2 * v + 1];
  }
}
void update(int v, int vl, int vr, int pos, char c, char old) {
  if (vl == vr) {
    t[v][old - 'a'] = 0;
    t[v][c - 'a'] = 1;
  } else {
    int vm = (vl + vr) / 2;
    if (pos <= vm) {
      update(2 * v, vl, vm, pos, c, old);
    } else {
      update(2 * v + 1, vm + 1, vr, pos, c, old);
    }
    t[v] = t[2 * v] | t[2 * v + 1];
  }
}
bitset<26> get(int v, int vl, int vr, int l, int r) {
  if (l <= vl && vr <= r) {
    return t[v];
  }
  if (vr < l || vl > r) {
    return 0;
  }
  int vm = (vl + vr) / 2;
  return get(2 * v, vl, vm, l, r) | get(2 * v + 1, vm + 1, vr, l, r);
}
int calc(bitset<26> b) {
  int res = 0;
  for (int i = 0; i < 26; i++) {
    if (b[i]) {
      res++;
    }
  }
  return res;
}
int main() {
  cin >> s >> q;
  build(1, 0, s.size() - 1);
  while (q--) {
    cin >> num;
    if (num == 1) {
      cin >> pos >> c;
      update(1, 0, s.size() - 1, pos - 1, c, s[pos - 1]);
      s[pos - 1] = c;
    } else {
      cin >> l >> r;
      cout << calc(get(1, 0, s.size() - 1, l - 1, r - 1)) << endl;
    }
  }
  return 0;
}
