#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;
vector<vector<int> > segtree(4 * N, vector<int>(26, 0));
string s;
void build(int node, int st, int en) {
  if (st == en) {
    segtree[node][s[st] - 'a']++;
    return;
  }
  int mid = (st + en) / 2;
  build(2 * node, st, mid);
  build(2 * node + 1, mid + 1, en);
  for (int i = 0; i < 26; i++) {
    segtree[node][i] = segtree[2 * node][i] + segtree[2 * node + 1][i];
  }
}
void update(int node, int st, int en, int pos, char New, char prev) {
  if (st == en) {
    segtree[node][prev - 'a']--;
    segtree[node][New - 'a']++;
    return;
  }
  int mid = (st + en) / 2;
  if (pos <= mid)
    update(2 * node, st, mid, pos, New, prev);
  else
    update(2 * node + 1, mid + 1, en, pos, New, prev);
  for (int i = 0; i < 26; i++) {
    segtree[node][i] = segtree[2 * node][i] + segtree[2 * node + 1][i];
  }
}
vector<int> query(int node, int st, int en, int l, int r) {
  if (l > en || r < st) {
    vector<int> a(26, 0);
    return a;
  }
  if (l <= st && en <= r) {
    vector<int> a(26, 0);
    for (int i = 0; i < 26; i++) {
      if (segtree[node][i] > 0) a[i]++;
    }
    return a;
  }
  int mid = (st + en) / 2;
  vector<int> leftans = query(2 * node, st, mid, l, r);
  vector<int> rightans = query(2 * node + 1, mid + 1, en, l, r);
  for (int i = 0; i < 26; i++) rightans[i] |= leftans[i];
  return rightans;
}
int32_t main() {
  cin >> s;
  int n = s.size();
  s = '#' + s;
  build(1, 1, n);
  int q, l, r, pos;
  char c;
  scanf("%d", &q);
  while (q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d %c", &pos, &c);
      update(1, 1, n, pos, c, s[pos]);
      s[pos] = c;
    } else {
      scanf("%d %d", &l, &r);
      vector<int> cnt = query(1, 1, n, l, r);
      int ans = 0;
      for (int i = 0; i < 26; i++) ans += cnt[i];
      printf("%d\n", ans);
    }
  }
  return 0;
}
