#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  getline(cin, s);
  map<char, set<int>> m;
  for (int i = 0; i < s.size(); i++) m[s[i]].insert(i + 1);
  int q;
  cin >> q;
  cin.ignore();
  while (q) {
    int query_type, pos, l, r;
    char x;
    cin >> query_type;
    if (query_type == 1) {
      cin >> pos;
      cin.ignore();
      cin >> x;
      m[s[pos - 1]].erase(pos);
      s[pos - 1] = x;
      m[x].insert(pos);
    } else {
      cin >> l >> r;
      int distinct = 0;
      for (int i = 97; i <= 122; i++) {
        auto lb = m[char(i)].lower_bound(l);
        if (lb != m[char(i)].end()) {
          if (*lb <= r) {
            distinct++;
          }
        }
      }
      cout << distinct << endl;
    }
    q--;
  }
}
