#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const double esp = 1e-8;
void solve();
void files() { solve(); }
int main() {
  std::ios::sync_with_stdio(false);
  std::cout << fixed << setprecision(20);
  files();
}
const int maxn = 1e5 + 7;
int n, t, m, k = sqrt(maxn), l, r;
char s[maxn], ch;
int ans[maxn], sum, num[200];
int qn;
struct query {
  int l, r, id, t;
} q[maxn];
int tn;
struct change {
  int pl;
  char val, oval;
} c[maxn];
bool cmp(query a, query b) {
  if (a.l / k != b.l / k) return a.l / k < b.l / k;
  if (a.r / k != b.r / k) return a.r / k < b.r / k;
  return a.t < b.t;
}
void add(char ch) {
  num[ch]++;
  if (num[ch] == 1) sum++;
}
void del(char ch) {
  num[ch]--;
  if (num[ch] == 0) sum--;
}
void addchange(int t) {
  int pl = c[t].pl, val = c[t].val;
  if (pl >= l && pl <= r) add(val), del(s[pl]);
  s[pl] = val;
}
void delchange(int t) {
  int pl = c[t].pl, val = c[t].oval;
  if (pl >= l && pl <= r) add(val), del(s[pl]);
  s[pl] = val;
}
void solve() {
  cin >> (s + 1) >> m;
  k = pow(strlen(s + 1), 2.0 / 3);
  for (int i = 1; i <= m; i++) {
    cin >> n;
    if (n == 1) {
      cin >> n >> ch;
      c[++tn].pl = n, c[tn].val = ch, c[tn].oval = s[n];
      s[n] = ch;
    } else {
      cin >> l >> r;
      qn++, q[qn] = {l, r, qn, tn};
    }
  }
  for (int i = tn; i >= 1; i--) s[c[i].pl] = c[i].oval;
  sort(q + 1, q + 1 + qn, cmp);
  l = 1, r = 0, t = 0;
  for (int i = 1; i <= qn; i++) {
    int pl = q[i].l, pr = q[i].r, pt = q[i].t;
    while (t < pt) addchange(++t);
    while (t > pt) delchange(t--);
    while (l > pl) add(s[--l]);
    while (r < pr) add(s[++r]);
    while (l < pl) del(s[l++]);
    while (r > pr) del(s[r--]);
    ans[q[i].id] = sum;
  }
  for (int i = 1; i <= qn; i++) cout << ans[i] << endl;
}
