#include <bits/stdc++.h>
using namespace std;
int tc, cs = 1;
const int N = 200005;
string gorom;
set<int> myset[30];
void processQuery(int q) {
  while (q--) {
    int l, r, option;
    char fuck;
    cin >> option;
    if (option == 1) {
      cin >> l >> fuck;
      myset[gorom[l - 1] - 'a'].erase(l);
      myset[fuck - 'a'].insert(l);
      gorom[l - 1] = fuck;
    } else {
      cin >> l >> r;
      int result = 0;
      for (int i = 0; i < 26; ++i) {
        auto itr = myset[i].lower_bound(l);
        if (itr != myset[i].end() && *itr >= l && *itr <= r) result++;
      }
      cout << result << endl;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> gorom;
  int q;
  for (int i = 0; i < gorom.size(); ++i) {
    myset[gorom[i] - 'a'].insert(i + 1);
  }
  cin >> q;
  processQuery(q);
  return 0;
}
