#include <bits/stdc++.h>
using namespace std;
int n, q, now, tut[10 + 5][10 + 5], st[4][57][100000 * 3], a[100000 + 5];
char s[100000 + 5];
int pai(char x) {
  if (x == 'A') return 0;
  if (x == 'T') return 1;
  if (x == 'G') return 2;
  if (x == 'C') return 3;
}
void build(int node, int bas, int son, int mod, int rem, int ch) {
  int tt = tut[mod][rem];
  if (bas == son) {
    if (bas % mod == rem && a[bas] == ch) {
      st[ch][tt][node] = 1;
    }
    return;
  }
  int orta = (bas + son) / 2;
  build(node * 2, bas, orta, mod, rem, ch);
  build(node * 2 + 1, orta + 1, son, mod, rem, ch);
  st[ch][tt][node] = st[ch][tt][node * 2] + st[ch][tt][node * 2 + 1];
}
int get(int node, int bas, int son, int x, int y, int mod, int rem, int ch) {
  int tt = tut[mod][rem];
  if (bas > y || son < x) return 0;
  if (bas >= x && son <= y) return st[ch][tt][node];
  int orta = (bas + son) / 2;
  return get(node * 2, bas, orta, x, y, mod, rem, ch) +
         get(node * 2 + 1, orta + 1, son, x, y, mod, rem, ch);
}
void up(int node, int bas, int son, int x, int y, int mod, int rem, int ch,
        int val) {
  int tt = tut[mod][rem];
  if (bas > y || son < x) return;
  if (bas >= x && son <= y) {
    st[ch][tt][node] = val;
    return;
  }
  int orta = (bas + son) / 2;
  up(node * 2, bas, orta, x, y, mod, rem, ch, val);
  up(node * 2 + 1, orta + 1, son, x, y, mod, rem, ch, val);
  st[ch][tt][node] = st[ch][tt][node * 2] + st[ch][tt][node * 2 + 1];
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    a[i] = pai(s[i]);
  }
  for (int i = 1; i <= 10; i++) {
    for (int j = i - 1; j >= 0; j--) {
      tut[i][j] = now++;
      for (int k = 0; k < 4; k++) {
        build(1, 1, n, i, j, k);
      }
    }
  }
  scanf("%d", &q);
  while (q--) {
    int x, y, ty;
    scanf("%d", &ty);
    if (ty == 1) {
      char c;
      scanf("%d %c", &x, &c);
      int val = a[x];
      a[x] = pai(c);
      for (int i = 1; i <= 10; i++) {
        up(1, 1, n, x, x, i, x % i, val, 0);
        up(1, 1, n, x, x, i, x % i, a[x], 1);
      }
    } else {
      scanf("%d %d %s", &x, &y, s + 1);
      int len = strlen(s + 1);
      int cev = 0;
      for (int i = 1; i <= len; i++) {
        cev += get(1, 1, n, x, y, len, (x + i - 1) % len, pai(s[i]));
      }
      printf("%d\n", cev);
    }
  }
}
