#include <bits/stdc++.h>
using namespace std;
string s;
const long long int N = 1e5 + 2;
long long int tree[4 * N][26];
void build(long long int node, long long int start, long long int end) {
  if (start == end) {
    tree[node][s[start] - 'a'] = 1;
    return;
  }
  long long int mid = (start + end) / 2;
  build(2 * node, start, mid);
  build(2 * node + 1, mid + 1, end);
  for (long long int i = 0; i < 26; i++) {
    if (tree[2 * node][i] > 0 || tree[2 * node + 1][i] > 0)
      tree[node][i] = 1;
    else
      tree[node][i] = 0;
  }
}
void update(long long int node, long long int start, long long int end,
            long long int idx, char ch) {
  if (start == end) {
    tree[node][s[start] - 'a'] = 0;
    s[start] = ch;
    tree[node][ch - 'a'] = 1;
    return;
  }
  long long int mid = (start + end) / 2;
  if (start <= idx && idx <= mid)
    update(2 * node, start, mid, idx, ch);
  else
    update(2 * node + 1, mid + 1, end, idx, ch);
  for (long long int i = 0; i < 26; i++) {
    if (tree[2 * node][i] > 0 || tree[2 * node + 1][i] > 0)
      tree[node][i] = 1;
    else
      tree[node][i] = 0;
  }
}
vector<long long int> query(long long int node, long long int start,
                            long long int end, long long int l,
                            long long int r) {
  if (start > end || start > r || end < l) {
    vector<long long int> tt(26, 0);
    return tt;
  }
  if (start >= l && end <= r) {
    vector<long long int> hash(26, 0);
    for (long long int i = 0; i < 26; i++) {
      if (tree[node][i] > 0) hash[i] = 1;
    }
    return hash;
  }
  long long int mid = (start + end) / 2;
  vector<long long int> left(26, 0);
  left = query(2 * node, start, mid, l, r);
  vector<long long int> right(26, 0);
  right = query(2 * node + 1, mid + 1, end, l, r);
  vector<long long int> curr(26, 0);
  for (long long int i = 0; i < 26; i++) {
    if (left[i] > 0 || right[i] > 0)
      curr[i] = 1;
    else
      curr[i] = 0;
  }
  return curr;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> s;
  long long int n = s.size();
  build(1, 0, n - 1);
  long long int q;
  cin >> q;
  while (q--) {
    long long int t;
    cin >> t;
    if (t == 1) {
      long long int pos;
      char ch;
      cin >> pos >> ch;
      pos--;
      update(1, 0, n - 1, pos, ch);
    } else {
      long long int l, r;
      cin >> l >> r;
      l--;
      r--;
      vector<long long int> qq(26, 0);
      qq = query(1, 0, n - 1, l, r);
      long long int cnt = 0;
      for (long long int i = 0; i < 26; i++)
        if (qq[i] > 0) cnt++;
      cout << cnt << "\n";
    }
  }
}
