#include <bits/stdc++.h>
const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;
int q, op, pos, r, x, len, l;
char ch[10], str[maxn];
int tr[26][maxn];
int lowbit(int x) { return x & (-x); }
void update(int x, int y, int n, int p) {
  for (int i = x; i <= n; i += lowbit(i)) tr[p][i] += y;
}
int getsum(int x, int p) {
  int ans = 0;
  for (int i = x; i; i -= lowbit(i)) ans += tr[p][i];
  return ans;
}
int main() {
  str[0] = 'a';
  scanf("%s\n%d", str + 1, &q);
  len = strlen(str);
  for (int i = 1; i < len; ++i) {
    update(i, 1, len, str[i] - 'a');
  }
  while (q--) {
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d %s", &pos, ch);
      update(pos, -1, len, str[pos] - 'a');
      str[pos] = ch[0];
      update(pos, 1, len, str[pos] - 'a');
    } else {
      scanf("%d %d", &l, &r);
      int ans = 0;
      for (int i = 0; i < 26; ++i) {
        if (getsum(r, i) - getsum(l - 1, i)) ++ans;
      }
      printf("%d\n", ans);
    }
  }
}
