#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long MOD = 1000000007;
double eps = 1e-12;
long long modu(long long a, long long b, long long c) {
  if (b == 0) return 1;
  if (b % 2) {
    return (a % c * modu(a, b - 1, c)) % c;
  } else {
    long long y = modu(a, b / 2, c);
    return (y * y) % c;
  }
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long ceil2(long long a, long long b) {
  long long res = a / b;
  if (b * res != a) res += (a > 0) & (b > 0);
  return res;
}
long long power(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2) {
    return a * power(a * a, b / 2);
  } else
    return power(a * a, b / 2);
}
void solve() {
  string s;
  cin >> s;
  set<long long> idx[26];
  for (auto x : idx) x.clear();
  long long n = s.size();
  for (long long i = 0; i < n; i++) {
    idx[s[i] - 'a'].insert(i);
  }
  long long q;
  cin >> q;
  while (q--) {
    long long query;
    cin >> query;
    if (query == 1) {
      long long index;
      char p;
      cin >> index >> p;
      index--;
      idx[(s[index] - 'a')].erase(index);
      s[index] = p;
      idx[(p - 'a')].insert(index);
    } else {
      long long l;
      long long r;
      cin >> l >> r;
      l--;
      r--;
      long long cnt = 0;
      for (long long i = 0; i < 26; i++) {
        if (idx[i].size()) {
          auto it = idx[i].lower_bound(l);
          if (it != idx[i].end() && ((*it) <= r)) cnt++;
        }
      }
      cout << cnt << endl;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
