#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 100005;
const long long mod = 1e9 + 7;
string s;
int q;
vector<set<int>> PosSet(28);
void unstopable() {
  cin >> s >> q;
  for (int i = 0; i < s.size(); ++i) {
    PosSet[s[i] - 'a'].insert(i);
  }
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int pos;
      char c;
      cin >> pos >> c;
      pos--;
      PosSet[s[pos] - 'a'].erase(pos);
      s[pos] = c;
      PosSet[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 = PosSet[i].lower_bound(l);
        if (it != PosSet[i].end() && *it <= r) cnt++;
      }
      cout << cnt << endl;
    }
  }
}
signed main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  unstopable();
}
