#include <bits/stdc++.h>
using ll = long long;
int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::string s;
  std::cin >> s;
  int n = s.length();
  std::vector<std::set<int>> adj(26);
  for (int i = 0; i < n; ++i) {
    int d = s[i] - 'a';
    adj[d].insert(i);
  }
  int q;
  std::cin >> q;
  while (q--) {
    int op;
    std::cin >> op;
    if (op == 1) {
      int pos;
      char c;
      std::cin >> pos >> c;
      --pos;
      int d = s[pos] - 'a';
      s[pos] = c;
      adj[d].erase(pos);
      adj[c - 'a'].insert(pos);
    } else {
      int l, r;
      std::cin >> l >> r;
      --l, --r;
      int ans = 0;
      for (int i = 0; i < 26; ++i) {
        if (adj[i].empty()) {
          continue;
        }
        auto it = adj[i].lower_bound(l);
        if (it == adj[i].end()) {
          continue;
        }
        int index = *it;
        if (index <= r) {
          ++ans;
        }
      }
      std::cout << ans << "\n";
    }
  }
}
