#include <bits/stdc++.h>
using namespace std;
int getMid(int s, int e) { return s + (e - s) / 2; }
int getSumUtil(int *st, int ss, int se, int qs, int qe, int si) {
  if (qs <= ss && qe >= se) return st[si];
  if (se < qs || ss > qe) return 0;
  int mid = getMid(ss, se);
  return getSumUtil(st, ss, mid, qs, qe, 2 * si + 1) +
         getSumUtil(st, mid + 1, se, qs, qe, 2 * si + 2);
}
void updateValueUtil(int *st, int ss, int se, int i, int diff, int si) {
  if (i < ss || i > se) return;
  st[si] = st[si] + diff;
  if (se != ss) {
    int mid = getMid(ss, se);
    updateValueUtil(st, ss, mid, i, diff, 2 * si + 1);
    updateValueUtil(st, mid + 1, se, i, diff, 2 * si + 2);
  }
}
void updateValue(int arr[], int *st, int n, int i, int new_val) {
  if (i < 0 || i > n - 1) {
    return;
  }
  int diff = new_val - arr[i];
  arr[i] = new_val;
  updateValueUtil(st, 0, n - 1, i, diff, 0);
}
int getSum(int *st, int n, int qs, int qe) {
  if (qs < 0 || qe > n - 1 || qs > qe) {
    return 0;
  }
  return getSumUtil(st, 0, n - 1, qs, qe, 0);
}
int constructSTUtil(int arr[], int ss, int se, int *st, int si) {
  if (ss == se) {
    st[si] = arr[ss];
    return arr[ss];
  }
  int mid = getMid(ss, se);
  st[si] = constructSTUtil(arr, ss, mid, st, si * 2 + 1) +
           constructSTUtil(arr, mid + 1, se, st, si * 2 + 2);
  return st[si];
}
int *constructST(int arr[], int n) {
  int x = (int)(ceil(log2(n)));
  int max_size = 2 * (int)pow(2, x) - 1;
  int *st = new int[max_size];
  constructSTUtil(arr, 0, n - 1, st, 0);
  return st;
}
int main() {
  string S;
  cin >> S;
  int n = S.length();
  int arr[26][n];
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < n; j++) {
      arr[i][j] = 0;
    }
  }
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < n; j++) {
      if ((int(S.at(j)) - 97) == i)
        arr[i][j] = 1;
      else
        arr[i][j] = 0;
    }
  }
  int *st[26];
  for (int i = 0; i < 26; i++) {
    st[i] = constructST(arr[i], n);
  }
  int Q;
  cin >> Q;
  for (int q = 0; q < Q; q++) {
    int a;
    cin >> a;
    if (a == 1) {
      int b;
      char c;
      cin >> b;
      cin >> c;
      updateValue(arr[int(S.at(b - 1)) - 97], st[int(S.at(b - 1)) - 97], n,
                  b - 1, 0);
      updateValue(arr[int(c) - 97], st[int(c) - 97], n, b - 1, 1);
      S.at(b - 1) = c;
    } else {
      int b;
      int d;
      cin >> b;
      cin >> d;
      int k = 0;
      for (int i = 0; i < 26; i++) {
        if (getSum(st[i], n, b - 1, d - 1) != 0) {
          k++;
        }
      }
      cout << k << endl;
    }
  }
  return 0;
}
