#include <bits/stdc++.h>
using namespace std;
const int MxN = 1e5 + 5;
string str;
int n;
bool t[4 * 100005][30];
int numOfOnes(vector<bool>* v) {
  int ans = 0;
  for (int i = 0; i < v->size(); i++) {
    ans += v->at(i);
  }
  return ans;
}
void* combine(int row1, int row2, int result_row) {
  for (int i = 0; i < 28; i++) {
    t[result_row][i] = t[row1][i] || t[row2][i];
  }
}
void build(int node, int a, int b) {
  if (a == b) {
    t[node][str[a] - 'a'] = 1;
    return;
  }
  int mid = (a + b) >> 1;
  build(node * 2, a, mid);
  build(node * 2 + 1, mid + 1, b);
  for (int i = 0; i <= 26; i++) {
    if (t[2 * node][i] == 1 || t[2 * node + 1][i] == 1) {
      t[node][i] = 1;
    }
  }
}
void query(int node, int a, int b, int i, int j, bool make[]) {
  if (a >= i and b <= j) {
    for (int i = 0; i <= 26; i++) make[i] = make[i] | t[node][i];
    return;
  }
  int mid = (a + b) >> 1;
  if (j <= mid) {
    query(2 * node, a, mid, i, j, make);
    return;
  } else if (i > mid) {
    query(2 * node + 1, mid + 1, b, i, j, make);
    return;
  } else {
    query(2 * node, a, mid, i, j, make);
    query(2 * node + 1, mid + 1, b, i, j, make);
    return;
  }
}
void update(int node, int a, int b, int pos, char val) {
  if (a == b and a == pos) {
    for (int i = 0; i <= 26; i++) t[node][i] = 0;
    t[node][val - 'a'] = 1;
    return;
  }
  int mid = (a + b) >> 1;
  if (pos <= mid)
    update(node * 2, a, mid, pos, val);
  else
    update(node * 2 + 1, mid + 1, b, pos, val);
  for (int i = 0; i <= 26; i++) {
    if (t[2 * node][i] == 1 || t[2 * node + 1][i] == 1) {
      t[node][i] = 1;
    } else
      t[node][i] = 0;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  memset(t, false, sizeof(t));
  int te;
  cin >> str;
  build(1, 0, str.size() - 1);
  cin >> te;
  for (int i = 0; i < te; i++) {
    int k;
    cin >> k;
    if (k == 1) {
      int a;
      char c;
      cin >> a >> c;
      update(1, 0, str.size() - 1, a - 1, c);
    } else {
      int a, b;
      cin >> a >> b;
      bool arr[30] = {0};
      query(1, 0, str.size() - 1, a - 1, b - 1, arr);
      int ans = 0;
      for (int i = 0; i < 30; i++) {
        if (arr[i]) ans++;
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
