#include <bits/stdc++.h>
using namespace std;
long long modularExponentiation(long long x, long long n, long long M) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return modularExponentiation((x * x) % M, n / 2, M);
  return (x * modularExponentiation((x * x) % M, (n - 1) / 2, M)) % M;
}
const long long N = 1000000;
long long n;
string s;
long long tree[2 * N];
long long seta(char c) {
  long long a = 0;
  long long f = c - 'a';
  a = 1 << f;
  return a;
}
void build(long long node, long long start, long long end) {
  if (start == end) {
    tree[node] = seta(s[start]);
  } else {
    long long mid = (start + end) / 2;
    build(2 * node, start, mid);
    build(2 * node + 1, mid + 1, end);
    tree[node] = tree[2 * node] | tree[2 * node + 1];
  }
}
void update(long long node, long long start, long long end, long long idx,
            char val) {
  if (start == end) {
    s[idx] = val;
    tree[node] = seta(val);
  } else {
    long long mid = (start + end) / 2;
    if (start <= idx and idx <= mid) {
      update(2 * node, start, mid, idx, val);
    } else {
      update(2 * node + 1, mid + 1, end, idx, val);
    }
    tree[node] = tree[2 * node] | tree[2 * node + 1];
  }
}
long long query(long long node, long long start, long long end, long long l,
                long long r) {
  if (r < start or end < l) {
    return 0;
  }
  if (l <= start and end <= r) {
    return tree[node];
  }
  long long mid = (start + end) / 2;
  long long p1 = query(2 * node, start, mid, l, r);
  long long p2 = query(2 * node + 1, mid + 1, end, l, r);
  return (p1 | p2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> s;
  n = s.size();
  build(1, 0, n - 1);
  long long q;
  cin >> q;
  while (q--) {
    long long x;
    cin >> x;
    if (x == 1) {
      long long y;
      char c;
      cin >> y >> c;
      update(1, 0, n - 1, y - 1, c);
    } else {
      long long y, z;
      cin >> y >> z;
      long long ans = query(1, 0, n - 1, y - 1, z - 1);
      long long co = 0;
      while (ans) {
        if (ans % 2 != 0) {
          co++;
        }
        ans /= 2;
      }
      cout << co << "\n";
    }
  }
}
