#include <bits/stdc++.h>
using namespace std;
long long vect[1000000], vect1[1000000], a[1000001][26] = {};
string s;
void build(long long node, long long start, long long end1) {
  if (start == end1) {
    vect[node] = 1;
    long long a1 = s[start] - 'a';
    if (a1 >= 0 && a1 <= 26) a[node][a1]++;
  } else {
    long long mid = (start + end1) / 2;
    build(2 * node, start, mid);
    build(2 * node + 1, mid + 1, end1);
    long long count1 = 0;
    for (int i = 0; i < 26; i++) {
      long long c2 = 2 * node;
      a[node][i] = a[c2][i] + a[c2 + 1][i];
      if (a[node][i] > 0) count1++;
    }
    vect[node] = count1;
  }
}
long long sac[26] = {};
void query(long long node, long long start, long long end1, long long first,
           long long second) {
  if (end1 < first || second < start)
    return;
  else if (start >= first && end1 <= second) {
    for (int i = 0; i < 26; i++) sac[i] += a[node][i];
    return;
  }
  long long mid = (start + end1) / 2;
  query(2 * node, start, mid, first, second);
  query(2 * node + 1, mid + 1, end1, first, second);
}
char c1;
void update(long long node, long long start, long long end1, long long index) {
  if (start == end1) {
    long long b = c1 - 'a';
    long long d = s[index] - 'a';
    a[node][d]--;
    a[node][b]++;
    s[index] = c1;
  } else {
    long long mid = (start + end1) / 2;
    if (index >= start && index <= mid)
      update(2 * node, start, mid, index);
    else
      update(2 * node + 1, mid + 1, end1, index);
    long long count1 = 0;
    for (int i = 0; i < 26; i++) {
      a[node][i] = a[2 * node][i] + a[2 * node + 1][i];
    }
  }
}
int main() {
  memset(vect, -1, sizeof vect);
  cin >> s;
  s = '#' + s;
  long long t;
  cin >> t;
  long long n = s.size();
  build(1, 1, n);
  while (t--) {
    long long q, f, l;
    cin >> q >> f;
    if (q == 1) {
      cin >> c1;
      update(1, 1, n, f);
    } else {
      cin >> l;
      query(1, 1, n, f, l);
      long long count1 = 0;
      for (int i = 0; i < 26; i++) {
        if (sac[i] != 0) count1++;
        sac[i] = 0;
      }
      cout << count1 << endl;
    }
  }
  return 0;
}
