#include <bits/stdc++.h>
using namespace std;
char s[100005];
int t[2000010][26];
void build(int node, int start, int end) {
  if (start == end) {
    t[node][s[start] - 'a'] = 1;
    return;
  } else {
    int mid = start + (end - start) / 2;
    build(2 * node, start, mid);
    build((2 * node) + 1, mid + 1, end);
    for (int i = 0; i < 26; i++) {
      t[node][i] = max(t[2 * node][i], t[(2 * node) + 1][i]);
    }
  }
}
void update(int node, int start, int end, int idx, char val) {
  if (start == end) {
    t[node][s[idx] - 'a'] = 0;
    s[idx] = val;
    t[node][s[idx] - 'a'] = 1;
    return;
  } else {
    int mid = start + (end - start) / 2;
    if (idx >= start && idx <= mid) {
      update(2 * node, start, mid, idx, val);
    } else {
      update((2 * node) + 1, mid + 1, end, idx, val);
    }
    for (int i = 0; i < 26; i++) {
      t[node][i] = max(t[2 * node][i], t[(2 * node) + 1][i]);
    }
  }
}
void query(int node, int start, int end, int l, int r, int c[]) {
  if (r < start || l > end) {
    return;
  }
  if (start >= l && end <= r) {
    for (int i = 0; i < 26; i++) {
      c[i] = max(c[i], t[node][i]);
    }
    return;
  }
  int mid = start + (end - start) / 2;
  query(2 * node, start, mid, l, r, c);
  query((2 * node) + 1, mid + 1, end, l, r, c);
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string str;
  cin >> str;
  int n = str.size();
  for (int i = 1; i <= n; i++) {
    s[i] = str[i - 1];
  }
  int test;
  cin >> test;
  build(1, 1, n);
  while (test > 0) {
    int type;
    cin >> type;
    if (type == 1) {
      int pos;
      char ch;
      cin >> pos >> ch;
      update(1, 1, n, pos, ch);
    } else {
      int l, r;
      cin >> l >> r;
      int c[26] = {0}, ans = 0;
      query(1, 1, n, l, r, c);
      for (int i = 0; i < 26; i++) {
        ans += c[i];
      }
      cout << ans << endl;
    }
    test--;
  }
  return 0;
}
