#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5;
int t, q;
set<int> s[26];
string str;
void change(int x, char ch) {
  char temp = str[x];
  s[temp - 'a'].erase(x);
  str[x] = ch;
  s[ch - 'a'].insert(x);
}
void query(int l, int r) {
  int ans = 0;
  for (int i = 0; i <= 25; i++) {
    set<int>::iterator it = s[i].lower_bound(l);
    if (it != s[i].end() && *it <= r) ans++;
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  while (cin >> str) {
    for (int i = 0; i <= 25; i++) {
      s[i].clear();
    }
    int len = str.size();
    for (int i = 0; i <= len - 1; i++) {
      s[str[i] - 'a'].insert(i);
    }
    cin >> q;
    int op;
    int l, r, pos;
    char ch;
    while (q--) {
      cin >> op;
      if (op == 1) {
        cin >> pos >> ch;
        change(pos - 1, ch);
      } else {
        cin >> l >> r;
        query(l - 1, r - 1);
      }
    }
  }
  return 0;
}
