#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
long long qpow(long long a, long long b, long long mod) {
  long long ret = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) ret = ret * a % mod;
    a = a * a % mod;
  }
  return ret;
}
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= c == '-';
  for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  x = f ? -x : x;
}
const int N = 1e5 + 10;
const int M = 5e3 + 10;
const int mod = (int)1e9 + 7;
const double eps = 1e-10;
const double pi = acos(-1.0);
struct Node {
  bool c[26];
} a[N << 2];
int n;
int b[N];
char s[N];
void Up(int rt) {
  for (int i = 0; i < (26); i++)
    a[rt].c[i] = (a[rt << 1].c[i] | a[rt << 1 | 1].c[i]);
}
void build(int rt, int l, int r) {
  memset(a[rt].c, 0, sizeof(a[rt].c));
  if (l == r) {
    a[rt].c[b[l]] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  Up(rt);
}
void change(int rt, int l, int r, int x, int v, int old) {
  if (l == r) {
    a[rt].c[old] = 0;
    a[rt].c[v] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    change(rt << 1, l, mid, x, v, old);
  else
    change(rt << 1 | 1, mid + 1, r, x, v, old);
  Up(rt);
}
Node work(Node a, Node b) {
  for (int i = 0; i < (26); i++) a.c[i] |= b.c[i];
  return a;
}
int cal(Node a) {
  int cnt = 0;
  for (int i = 0; i < (26); i++)
    if (a.c[i]) cnt++;
  return cnt;
}
Node query(int rt, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    return a[rt];
  }
  Node ans;
  memset(ans.c, 0, sizeof(ans.c));
  int mid = (l + r) >> 1;
  if (L <= mid) ans = query(rt << 1, l, mid, L, R);
  if (mid < R) ans = work(ans, query(rt << 1 | 1, mid + 1, r, L, R));
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s + 1;
  n = strlen(s + 1);
  for (int i = 1; i <= (n); i++) {
    b[i] = s[i] - 'a';
  }
  build(1, 1, n);
  int q;
  int ty, x, y;
  char ss[5];
  cin >> q;
  while (q--) {
    cin >> ty >> x;
    if (ty == 1) {
      cin >> ss;
      change(1, 1, n, x, ss[0] - 'a', b[x]);
      b[x] = ss[0] - 'a';
    } else {
      cin >> y;
      Node ans = query(1, 1, n, x, y);
      printf("%d\n", cal(ans));
    }
  }
  return 0;
}
