#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
long long qpow(long long a, long long b) {
  long long s = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      s = s * a;
    }
    a = a * a;
    b = b >> 1;
  }
  return s;
}
long long qpowmod(long long a, long long b, long long c) {
  long long res, t;
  res = 1;
  t = a % c;
  while (b) {
    if (b & 1) {
      res = res * t % c;
    }
    t = t * t % c;
    b >>= 1;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long read() {
  long long k = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    k = k * 10 + ch - '0';
    ch = getchar();
  }
  return k * f;
}
inline void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
int q;
set<int> s[30];
int main() {
  string a;
  cin >> a;
  int len = a.length();
  for (int i = 1; i <= len; i++) {
    s[a[i - 1] - 'a'].insert(i);
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int cnt;
    cin >> cnt;
    if (cnt == 1) {
      int pos;
      char str;
      cin >> pos >> str;
      s[a[pos - 1] - 'a'].erase(pos);
      a[pos - 1] = str;
      s[str - 'a'].insert(pos);
    } else {
      int l, r, ans = 0;
      cin >> l >> r;
      for (int j = 0; j <= 25; j++) {
        set<int>::iterator it = s[j].lower_bound(l);
        if (it != s[j].end() && *it <= r) {
          ans++;
        }
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
