#include <bits/stdc++.h>
using namespace std;
struct node {
  int b[30], ans;
};
string s;
node temp1;
node merge(node seg1, node seg2) {
  node temp;
  temp.ans = 0;
  for (int i = 0; i < 26; i++) {
    temp.b[i] = seg1.b[i] + seg2.b[i];
    if (temp.b[i] > 0) temp.ans++;
  }
  return temp;
}
void build(node seg[], int pos, int l, int r) {
  if (l == r) {
    seg[pos].b[s[l] - 'a'] = 1;
    seg[pos].ans = 1;
    return;
  }
  int pos1 = pos << 1 | 1;
  int pos2 = pos1 + 1;
  int mid = (l + r) >> 1;
  build(seg, pos1, l, mid);
  build(seg, pos2, mid + 1, r);
  seg[pos] = merge(seg[pos1], seg[pos2]);
  return;
}
node query(node seg[], int pos, int l, int r, int l1, int r1) {
  int mid = (l + r) >> 1;
  if (l1 <= l && r1 >= r) return seg[pos];
  if (l1 > r || r1 < l) {
    return temp1;
  }
  int pos1 = pos << 1 | 1;
  return merge(query(seg, pos1, l, mid, l1, r1),
               query(seg, pos1 + 1, mid + 1, r, l1, r1));
}
void update(node seg[], int pos, int l, int r, int x, char ele) {
  if (l > r) return;
  if (l > x || r < x) return;
  if (l == r) {
    seg[pos].b[s[x] - 'a']--;
    if (seg[pos].b[s[x] - 'a'] == 0) seg[pos].ans--;
    seg[pos].b[ele - 'a']++;
    if (seg[pos].b[ele - 'a'] == 1) seg[pos].ans++;
    return;
  }
  int mid = (l + r) >> 1;
  int pos1 = pos << 1 | 1;
  int pos2 = (pos + 1) << 1;
  update(seg, pos1, l, mid, x, ele);
  update(seg, pos2, mid + 1, r, x, ele);
  seg[pos] = merge(seg[pos1], seg[pos2]);
  return;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  cin >> s;
  int n = s.size();
  int j, q;
  node seg[4 * n + 5];
  for (int i = 0; i < 4 * n + 5; i++) {
    seg[i].ans = 0;
    for (j = 0; j < 26; j++) seg[i].b[j] = 0;
  }
  build(seg, 0, 0, n - 1);
  cin >> q;
  while (q--) {
    int t1;
    cin >> t1;
    if (t1 == 1) {
      int t2;
      char c;
      cin >> t2 >> c;
      update(seg, 0, 0, n - 1, t2 - 1, c);
      s[t2 - 1] = c;
    } else {
      int t2, t3;
      cin >> t2 >> t3;
      cout << query(seg, 0, 0, n - 1, t2 - 1, t3 - 1).ans << "\n";
    }
  }
}
