#include <bits/stdc++.h>
using namespace std;
const int64_t N = 1e5 + 10, sq = 275;
int64_t q, n;
string second;
char ch;
int64_t pos, l, r;
int64_t a[N], ans[N / sq];
void up(int64_t x) {
  ans[x] = 0;
  for (int64_t i = 0; i < sq && x * sq + i < second.size(); i++) {
    ans[x] |= (1 << a[x * sq + i]);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> second >> q;
  for (int64_t i = 0; i < second.size(); i++) {
    a[i] = second[i] - 'a';
  }
  for (int64_t i = 0; i < (second.size() + sq - 1) / sq; i++) {
    up(i);
  }
  while (q--) {
    cin >> n;
    if (n == 1) {
      cin >> pos >> ch;
      pos--;
      second[pos] = ch;
      a[pos] = ch - 'a';
      up(pos / sq);
    } else {
      int64_t Ans = 0;
      cin >> l >> r;
      l--;
      if (l / sq == r / sq) {
        while (l < r) {
          Ans = (Ans | (1 << a[l]));
          l++;
        }
        cout << __builtin_popcount(Ans) << '\n';
        continue;
      }
      while (l % sq != 0) {
        Ans = (Ans | (1 << a[l]));
        l++;
      }
      while (r % sq != 0) {
        Ans = (Ans | (1 << a[r - 1]));
        r--;
      }
      for (int64_t i = l / sq; i < r / sq; i++) {
        Ans |= ans[i];
      }
      cout << __builtin_popcount(Ans) << '\n';
    }
  }
}
