#include <bits/stdc++.h>
using namespace std;
const int K = 30;
const int N = 1e5 + 7;
string s;
int t[4 * N][K];
void build(int v, int l, int r, int to) {
  if (l == r) {
    if (int(s[l] - 'a') == to) {
      t[v][to] = 1;
    } else {
      t[v][to] = 0;
    }
  } else {
    int m = (r + l) >> 1;
    build(v + v + 1, l, m, to);
    build(v + v + 2, m + 1, r, to);
    t[v][to] = t[v + v + 1][to] + t[v + v + 2][to];
  }
}
void update(int v, int l, int r, int pos, int val, int to) {
  if (l == r) {
    t[v][to] = val;
  } else {
    int m = (r + l) >> 1;
    if (pos <= m) {
      update(v + v + 1, l, m, pos, val, to);
    } else {
      update(v + v + 2, m + 1, r, pos, val, to);
    }
    t[v][to] = t[v + v + 1][to] + t[v + v + 2][to];
  }
}
int findSum(int v, int l, int r, int tl, int tr, int to) {
  if (tl > tr) return 0;
  if (l == tl && r == tr) {
    return t[v][to];
  } else {
    int m = (r + l) >> 1;
    int t1 = findSum(v + v + 1, l, m, tl, min(tr, m), to);
    int t2 = findSum(v + v + 2, m + 1, r, max(tl, m + 1), tr, to);
    return t1 + t2;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s;
  int n = s.size();
  for (int i = 0; i < K; ++i) {
    build(0, 0, N - 1, i);
  }
  int q;
  cin >> q;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int a;
      char b;
      cin >> a;
      --a;
      cin >> b;
      int to = int(b - 'a');
      for (int i = 0; i < K; ++i) {
        if (i == to) {
          update(0, 0, N - 1, a, 1, to);
        } else {
          update(0, 0, N - 1, a, 0, i);
        }
      }
    } else {
      int l, r;
      cin >> l >> r;
      --l;
      --r;
      int ans = 0;
      for (int i = 0; i < K; ++i) {
        ans += (findSum(0, 0, N - 1, l, r, i) > 0);
      }
      cout << ans << endl;
    }
  }
}
