#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
void print() {}
template <class H, class... T>
void print(H&& h, T&&... t) {
  cout << h << " \n"[sizeof...(t) == 0];
  print(forward<T>(t)...);
}
struct BIT {
 private:
  int n, n2;
  vector<long long> bit;

 public:
  BIT(long long N) {
    n = N;
    bit.assign(n + 1, 0);
    n2 = 1;
    while (n2 * 2 <= n) n2 *= 2;
  }
  long long sum(long long x) {
    long long res = 0;
    for (long long i = x; i > 0; i -= i & -i) res += bit[i];
    return res;
  }
  void add(long long x, long long v) {
    if (x == 0) return;
    for (long long i = x; i <= n; i += i & -i) bit[i] += v;
  }
  long long lower_bound(long long w) {
    if (w <= 0) return 0;
    long long x = 0;
    for (long long k = n2; k > 0; k /= 2) {
      if (x + k <= n && bit[x + k] < w) {
        w -= bit[x + k];
        x += k;
      }
    }
    return x + 1;
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  long long Q;
  cin >> Q;
  long long N = S.size();
  vector<BIT> bit;
  for (long long i = (0); i < (26); i++) {
    BIT b(100010);
    bit.push_back(b);
  }
  for (long long i = (0); i < (N); i++) {
    bit[S[i] - 'a'].add(i + 1, 1);
  }
  while (Q--) {
    long long n;
    cin >> n;
    if (n == 1) {
      long long pos;
      char c;
      cin >> pos >> c;
      bit[S[pos - 1] - 'a'].add(pos, -1);
      bit[c - 'a'].add(pos, 1);
      S[pos - 1] = c;
    } else {
      long long l, r;
      cin >> l >> r;
      long long cnt = 0;
      for (long long i = (0); i < (26); i++) {
        if (bit[i].sum(r) - bit[i].sum(l - 1) > 0) cnt++;
      }
      print(cnt);
    }
  }
}
