#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e15 + 7;
const ll N = 3e5 + 5;
string s;
vector<set<int>> alpha(27);
int n;
void cnt() {
  for (int i = 0; i < n; i++) {
    alpha[s[i] - 'a'].insert(i);
  }
}
void update(char c, int pos) {
  alpha[s[pos] - 'a'].erase(pos);
  s[pos] = c;
  alpha[c - 'a'].insert(pos);
}
void cal(int l, int r) {
  int ans = 0;
  for (int i = 0; i < 26; i++) {
    auto id = alpha[i].lower_bound(l);
    if (alpha[i].find(*id) == alpha[i].end()) continue;
    if (l <= *id && *id <= r && alpha[i].size()) {
      ans++;
    }
  }
  cout << ans << endl;
}
void solve() {
  cin >> s;
  n = s.size();
  cnt();
  int m, st, l, r, pos;
  char c;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> st;
    if (st == 1) {
      cin >> pos >> c;
      pos--;
      update(c, pos);
    } else {
      cin >> l >> r;
      l--, r--;
      cal(l, r);
    }
  }
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
