#include <bits/stdc++.h>
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int exp(long long int x, long long int y) {
  long long int res = 1;
  x = x % 1000000007;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res;
}
using namespace std;
struct util {
  long long int fa[26] = {0};
};
util tree[4 * 100005];
string s;
void build(long long int v, long long int tl, long long int tr) {
  if (tl == tr) {
    tree[v].fa[s[tl] - 'a']++;
    return;
  }
  long long int tm = (tl + tr) / 2;
  ;
  build(2 * v, tl, tm);
  build(2 * v + 1, tm + 1, tr);
  for (long long int i = 0; i < 26; i++)
    tree[v].fa[i] = tree[2 * v].fa[i] + tree[2 * v + 1].fa[i];
}
void update(long long int v, long long int tl, long long int tr,
            long long int pos, char ch) {
  if (tl == tr) {
    tree[v].fa[s[pos] - 'a'] = 0;
    s[tl] = ch;
    tree[v].fa[ch - 'a'] = 1;
    return;
  }
  long long int tm = (tl + tr) / 2;
  if (pos <= tm)
    update(2 * v, tl, tm, pos, ch);
  else
    update(2 * v + 1, tm + 1, tr, pos, ch);
  for (long long int i = 0; i < 26; i++)
    tree[v].fa[i] = tree[2 * v].fa[i] + tree[2 * v + 1].fa[i];
}
util query(long long int v, long long int tl, long long int tr, long long int l,
           long long int r) {
  if (tl > r || tr < l) {
    util temp;
    for (long long int i = 0; i < 26; i++) temp.fa[i] = 0;
    return temp;
  }
  if (tl >= l && tr <= r) return tree[v];
  int tm = (tl + tr) / 2;
  util a, b, c;
  a = query(2 * v, tl, tm, l, r);
  b = query(2 * v + 1, tm + 1, tr, l, r);
  for (long long int i = 0; i < 26; i++) c.fa[i] = a.fa[i] + b.fa[i];
  return c;
}
int main() {
  cin >> s;
  char ch;
  long long int q, i, l, r, ans, ind, n = s.size();
  build(1, 0, n - 1);
  cin >> q;
  while (q--) {
    cin >> i;
    if (i == 1) {
      cin >> ind >> ch;
      update(1, 0, n - 1, ind - 1, ch);
    } else {
      cin >> l >> r;
      util temp = query(1, 0, n - 1, l - 1, r - 1);
      ans = 0;
      for (long long int i = 0; i < 26; i++) {
        if (temp.fa[i] > 0) ans++;
      }
      cout << ans << endl;
    }
  }
}
