#include <bits/stdc++.h>
using namespace std;
char words[100005];
int length;
int query;
int bit_char[27][100005];
void update_bit(int tree, int spot, int value) {
  while (spot <= length) {
    bit_char[tree][spot] += value;
    spot += spot & (-spot);
  }
}
int get_bit(int tree, int spot) {
  int sums = 0;
  while (spot > 0) {
    sums += bit_char[tree][spot];
    spot &= spot - 1;
  }
  return sums;
}
void prepare() {
  for (int j = 0; j < 26; j++)
    for (int i = 1; i <= length; i++) bit_char[j][i] = 0;
  for (int i = 1; i <= length; i++) update_bit(words[i] - 'a', i, 1);
}
void command_one() {
  int pos;
  char new_char;
  scanf("%d %c", &pos, &new_char);
  update_bit(words[pos] - 'a', pos, -1);
  words[pos] = new_char;
  update_bit(words[pos] - 'a', pos, 1);
}
void command_two() {
  int tail, head;
  scanf("%d %d", &tail, &head);
  int counter = 0;
  for (int j = 0; j < 26; j++)
    counter += (get_bit(j, head) - get_bit(j, tail - 1) > 0);
  printf("%d\n", counter);
}
int main() {
  scanf("%s", words + 1);
  length = strlen(words + 1);
  prepare();
  scanf("%d", &query);
  int command;
  for (int i = 1; i <= query; i++) {
    scanf("%d", &command);
    if (command == 1)
      command_one();
    else
      command_two();
  }
}
