#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
const int MOD = 1e9 + 7;
vector<long long> vector_input(long long n) {
  vector<long long> v;
  for (long long i = 0; i < n; i++) {
    long long num;
    cin >> num;
    v.push_back(num);
  }
  return v;
}
void input() {
  string s;
  int q;
  cin >> s;
  cin >> q;
  long long l = s.length();
  set<int> s1[26];
  s = "." + s;
  for (int i = 1; i <= l; i++) {
    s1[s[i] - 'a'].insert(i);
  }
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int pos;
      char c;
      cin >> pos >> c;
      s1[s[pos] - 'a'].erase(pos);
      s[pos] = c;
      s1[s[pos] - 'a'].insert(pos);
    } else {
      int l, r;
      cin >> l >> r;
      int ans = 0;
      for (int i = 0; i < 26; i++) {
        auto it = s1[i].lower_bound(l);
        if (it == s1[i].end()) continue;
        int x = *it;
        if (x <= r) ans++;
      }
      cout << ans << '\n';
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(12);
  input();
}
