#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
using namespace std;
int solve() {
  string s;
  cin >> s;
  vector<set<int>> se(26);
  for (int i = 0; i < int(s.size()); i++) {
    se[s[i] - 'a'].insert(i);
  }
  int q;
  cin >> q;
  for (int k = 0; k < q; k++) {
    int a;
    cin >> a;
    if (a == 1) {
      int pos;
      char c;
      cin >> pos >> c;
      --pos;
      se[s[pos] - 'a'].erase(pos);
      s[pos] = c;
      se[s[pos] - 'a'].insert(pos);
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      int cnt = 0;
      for (int i = 0; i < 26; i++) {
        auto it = se[i].lower_bound(l);
        if (it != se[i].end() && *it <= r) cnt++;
      }
      cout << cnt << "\n";
    }
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
}
