#include <bits/stdc++.h>
using namespace std;
set<int> s[26];
char a[100005];
int main() {
  scanf("%s", a);
  int n = strlen(a);
  for (int i = 0; i < n; i++) {
    s[a[i] - 'a'].insert(i);
  }
  int T;
  scanf("%d", &T);
  while (T--) {
    char c;
    int op, L, R;
    scanf("%d%d ", &op, &L);
    L -= 1;
    if (op == 1) {
      scanf("%c", &c);
      s[a[L] - 'a'].erase(L);
      a[L] = c;
      s[a[L] - 'a'].insert(L);
    } else {
      scanf("%d", &R);
      int ans = 0;
      for (int i = 0; i < 26; i++) {
        auto it = s[i].lower_bound(L);
        if (it != s[i].end() && *it < R) ans++;
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
