#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int maxm = 450;
char s[maxn];
int n, q, c;
char ch;
int x, y, L, R;
char e[20];
int l[maxm], r[maxm], p[maxn];
int num, cnt;
int a[maxm][12][12][4];
inline int getint(char c) {
  if (c == 'A') return 0;
  if (c == 'T') return 1;
  if (c == 'G') return 2;
  if (c == 'C') return 3;
}
void update(int x, char ch) {
  int po = p[x];
  for (int k = 1; k <= 10; k++) {
    int pos = (x - l[po]) % k + 1;
    a[po][k][pos][getint(s[x])]--;
  }
  s[x] = ch;
  for (int k = 1; k <= 10; k++) {
    int pos = (x - l[po]) % k + 1;
    a[po][k][pos][getint(s[x])]++;
  }
}
void query(int L, int R) {
  int res = 0;
  int len = strlen(e + 1);
  if (p[L] == p[R]) {
    for (int i = L; i <= R; i++)
      if (s[i] == e[(i - L) % len + 1]) res++;
    printf("%d\n", res);
    return;
  }
  int pl = p[L];
  int pr = p[R];
  for (int i = L; i <= r[pl]; i++)
    if (s[i] == e[(i - L) % len + 1]) res++;
  for (int i = l[pr]; i <= R; i++)
    if (s[i] == e[(i - L) % len + 1]) res++;
  for (int i = pl + 1; i <= pr - 1; i++) {
    int k = l[i] - L;
    for (int j = 1; j <= len; j++) {
      int kk = ((j - k) % len + len) % len;
      if (!kk) kk = len;
      res += a[i][len][kk][getint(e[j])];
    }
  }
  printf("%d\n", res);
  return;
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  cnt = (int)sqrt(n);
  num = n / cnt + (n % cnt ? 1 : 0);
  for (int i = 1; i < num; i++) {
    l[i] = (i - 1) * cnt + 1;
    r[i] = i * cnt;
  }
  l[num] = (num - 1) * cnt + 1;
  r[num] = n;
  for (int i = 1; i <= num; i++) {
    for (int j = l[i]; j <= r[i]; j++) {
      p[j] = i;
      for (int k = 1; k <= 10; k++) {
        int pos = (j - l[i]) % k + 1;
        a[i][k][pos][getint(s[j])]++;
      }
    }
  }
  cin >> q;
  while (q--) {
    scanf("%d", &c);
    if (c == 1) {
      scanf("%d %c", &x, &ch);
      update(x, ch);
    } else {
      scanf("%d%d%s", &L, &R, e + 1);
      query(L, R);
    }
  }
  return 0;
}
