#include <bits/stdc++.h>
using namespace std;
string s;
int n, m;
int Tree[200200 << 2];
void Build(int Now, int Start, int End) {
  if (Start == End) {
    Tree[Now] = (1LL << (s[Start] - 'a'));
    return;
  }
  int Mid = Start + End >> 1;
  Build(Now << 1, Start, Mid);
  Build(Now << 1 | 1, Mid + 1, End);
  Tree[Now] = Tree[Now << 1] | Tree[Now << 1 | 1];
}
int Query(int i, int j, int Now, int Start, int End) {
  if (End < i || Start > j) {
    return 0;
  }
  if (Start >= i && End <= j) {
    return Tree[Now];
  }
  int Mid = Start + End >> 1;
  int TryLeft = Query(i, j, Now << 1, Start, Mid);
  int TryRight = Query(i, j, Now << 1 | 1, Mid + 1, End);
  return (TryLeft | TryRight);
}
void Update(int i, int j, int Now, int Start, int End, char Val) {
  if (End < i || Start > j) return;
  if (Start == End && Start == i) {
    Tree[Now] = 0;
    Tree[Now] = (1LL << (Val - 'a'));
    return;
  }
  int Mid = Start + End >> 1;
  Update(i, j, Now << 1, Start, Mid, Val);
  Update(i, j, Now << 1 | 1, Mid + 1, End, Val);
  Tree[Now] = Tree[Now << 1] | Tree[Now << 1 | 1];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  n = s.size();
  Build(1, 0, s.size() - 1);
  cin >> m;
  while (m--) {
    int x;
    cin >> x;
    if (x == 1) {
      int y;
      char T;
      cin >> y;
      cin >> T;
      y--;
      Update(y, y, 1, 0, n - 1, T);
      int Sum = 0;
    } else {
      int Left, Right;
      cin >> Left >> Right;
      Left--;
      Right--;
      int Sum = 0;
      int tt = Query(Left, Right, 1, 0, n - 1);
      cout << __builtin_popcount(tt) << endl;
    }
  }
}
