#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',' << endl;
  __print(x.second);
  cerr << '}' << endl;
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}" << endl;
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", " << endl;
  _print(v...);
}
void solve() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<set<int>> count(26);
  for (int i = 0; i < s.size(); i++) {
    int cr = s[i] - 'a';
    count[cr].insert(i + 1);
  }
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      int pos;
      cin >> pos;
      char c;
      cin >> c;
      int ci = c - 'a';
      int cur = s[pos - 1] - 'a';
      if (count[cur].find(pos) != count[cur].end()) count[cur].erase(pos);
      count[ci].insert(pos);
      s[pos - 1] = c;
    } else {
      int l, r;
      cin >> l >> r;
      int ans = 0;
      for (int i = 0; i < 26; i++) {
        auto itl = count[i].lower_bound(l);
        auto itr = count[i].upper_bound(r);
        if (itl == count[i].end()) {
          continue;
        }
        if (itr == count[i].end()) {
          ans++;
        } else {
          if (itl != itr) ans++;
        }
      }
      cout << ans << endl;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
