#include <bits/stdc++.h>
using namespace std;
const int N = 100008;
int a[11][10][4][N], len;
char b[N], c[N];
int addx(int p1, int p2, int p3, int x, int y) {
  while (x <= len) {
    a[p1][p2][p3][x] += y;
    x += x & (-x);
  }
  return 0;
}
int sumx(int p1, int p2, int p3, int x) {
  int y = 0;
  while (x > 0) {
    y += a[p1][p2][p3][x];
    x -= x & (-x);
  }
  return y;
}
int pan(char x) {
  if (x == 'A')
    return 0;
  else if (x == 'G')
    return 1;
  else if (x == 'C')
    return 2;
  return 3;
}
int main(void) {
  int i, j, k, now, n, p, p1, p2, ll;
  scanf("%s", b + 1);
  len = strlen(b + 1);
  for (i = 1; i <= len; i++) {
    now = pan(b[i]);
    for (j = 1; j <= 10; j++) addx(j, i % j, now, i, 1);
  }
  scanf("%d", &n);
  while (n--) {
    scanf("%d", &p);
    if (p == 1) {
      scanf("%d%s", &p1, c + 1);
      for (j = 1; j <= 10; j++) {
        addx(j, p1 % j, pan(b[p1]), p1, -1);
        addx(j, p1 % j, pan(c[1]), p1, 1);
      }
      b[p1] = c[1];
    } else {
      scanf("%d%d%s", &p1, &p2, c + 1);
      k = 0;
      ll = strlen(c + 1);
      for (i = 1; c[i]; i++)
        k += sumx(ll, (p1 + i - 1) % ll, pan(c[i]), p2) -
             sumx(ll, (p1 + i - 1) % ll, pan(c[i]), p1 - 1);
      printf("%d\n", k);
    }
  }
  return 0;
}
