#include <bits/stdc++.h>
using namespace std;
const int N = 1e5, num = 26;
vector<int> t[4 * N];
vector<int> make_data(char c) {
  vector<int> v(num, 0);
  v[c - 'a'] = 1;
  return v;
}
vector<int> combine(vector<int>& v1, vector<int>& v2) {
  vector<int> v(num, 0);
  for (int i = 0; i < num; ++i) v[i] = v1[i] + v2[i];
  return v;
}
void build_tree(string& s, int v, int tl, int tr) {
  if (tl == tr) {
    t[v] = make_data(s[tl]);
  } else {
    int tm = (tl + tr) / 2;
    build_tree(s, 2 * v, tl, tm);
    build_tree(s, 2 * v + 1, tm + 1, tr);
    t[v] = combine(t[2 * v], t[2 * v + 1]);
  }
}
void update(int v, int tl, int tr, int pos, char c) {
  if (tl == tr) {
    t[v] = make_data(c);
  } else {
    int tm = (tl + tr) / 2;
    if (pos <= tm)
      update(2 * v, tl, tm, pos, c);
    else
      update(2 * v + 1, tm + 1, tr, pos, c);
    t[v] = combine(t[2 * v], t[2 * v + 1]);
  }
}
vector<int> get(int v, int tl, int tr, int l, int r) {
  if (l > r) return vector<int>(num, 0);
  if (l == tl && r == tr) return t[v];
  int tm = (tl + tr) / 2;
  vector<int> v1 = get(2 * v, tl, tm, l, min(tm, r));
  vector<int> v2 = get(2 * v + 1, tm + 1, tr, max(tm + 1, l), r);
  return combine(v1, v2);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  build_tree(s, 1, 0, n - 1);
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    if (a == 1) {
      char c;
      cin >> c;
      update(1, 0, n - 1, b - 1, c);
    } else {
      int c;
      cin >> c;
      vector<int> v = get(1, 0, n - 1, b - 1, c - 1);
      int cnt = 0;
      for (int i = 0; i < v.size(); ++i) {
        if (v[i]) cnt++;
      }
      cout << cnt << endl;
    }
  }
  return 0;
}
