#include <bits/stdc++.h>
const long double pie = 3.1415926535;
using namespace std;
long long fpow(long long n, long long p) {
  long long m = 1;
  while (p) {
    if (p % 2) m *= n;
    p >>= 1;
    n *= n;
  }
  return m;
}
bool br1, br2, br;
char ch, ch1, ch2;
long long n, k, x, y, z, mini, maxi, l, ind, ini, sum, t, len, r, w, imini, m;
string s, s1, s2;
set<long long> st[26];
void solve() {
  cin >> s >> m;
  n = s.length();
  for (long long i = 0; i < n; i++) {
    st[s[i] - 'a'].insert(i);
  }
  while (m--) {
    cin >> w;
    if (w == 1) {
      cin >> x >> ch;
      st[s[x - 1] - 'a'].erase(x - 1);
      st[ch - 'a'].insert(x - 1);
      s[x - 1] = ch;
    } else {
      cin >> x >> y;
      x--;
      y--;
      k = 0;
      for (long long i = 0; i < 26; i++) {
        if ((st[i].upper_bound(y)) != (st[i].upper_bound(x - 1))) k++;
      }
      cout << k << endl;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  solve();
  return 0;
}
