#include <bits/stdc++.h>
using namespace std;
struct fenwick {
  vector<int> tree[26];
  int N;
  fenwick(int n) {
    N = n;
    for (int i = 0; i < 26; i++) tree[i].resize(n + 1);
  }
  void add(int row, int val, int pos) {
    while (pos <= N) {
      tree[row][pos] += val;
      pos += pos & -pos;
    }
  }
  int sumq(int row, int b) {
    int sum = 0;
    while (b > 0) {
      sum += tree[row][b];
      b -= b & -b;
    }
    return sum;
  }
  int sum(int row, int a, int b) {
    if (a == 1)
      return sumq(row, b);
    else
      return sumq(row, b) - sumq(row, a - 1);
  }
};
int main() {
  string in;
  cin >> in;
  in.insert(0, "#");
  int q;
  cin >> q;
  fenwick f(in.size());
  for (int i = 1; i < in.size(); i++) f.add(in[i] - 'a', 1, i);
  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    if (a == 1) {
      int b;
      char c;
      cin >> b >> c;
      f.add(in[b] - 'a', -1, b);
      in[b] = c;
      f.add(c - 'a', 1, b);
    } else {
      int l, r;
      cin >> l >> r;
      int sol = 0;
      for (int i = 0; i < 26; i++) {
        int count = f.sum(i, l, r);
        if (count > 0) sol++;
      }
      cout << sol << "\n";
    }
  }
  return 0;
}
