#include <bits/stdc++.h>
int ds[4][12][12][100100];
char s[100100];
int n;
int bit_sum_aux(int* bit, int k) {
  int s = 0;
  while (k >= 1) {
    s += bit[k];
    k -= k & -k;
  }
  return s;
}
void bit_inc(int* bit, int k, int x) {
  k++;
  while (k <= n) {
    bit[k] += x;
    k += k & -k;
  }
}
int bit_sum(int* bit, int l, int r) {
  l++, r++;
  return bit_sum_aux(bit, r) - bit_sum_aux(bit, l - 1);
}
int query_aux(int l, int r, int c, int p, int m) {
  int* bit = ds[c][p][m];
  return bit_sum(bit, l, r);
}
void build2(int m, int p, int c) {
  int* bit = ds[c][p][m];
  for (int i = p; i < n; i += m)
    if (s[i] == c) bit_inc(bit, i, 1);
}
void build(void) {
  for (int i = 1; i <= 10; i++)
    for (int j = 0; j < i; j++)
      for (int k = 0; k < 4; k++) build2(i, j, k);
}
void update(int p, int c) {
  int prev_c = s[p];
  s[p] = c;
  for (int i = 1; i <= 10; i++) {
    bit_inc(ds[prev_c][p % i][i], p, -1);
    bit_inc(ds[c][p % i][i], p, 1);
  }
}
int query(char* e, int len, int l, int r) {
  int s = 0;
  for (int i = l; i < l + len; i++)
    s += query_aux(l, r, e[i - l], i % len, len);
  return s;
}
int convert(int c) {
  static int m[512];
  m['A'] = 0;
  m['T'] = 1;
  m['G'] = 2;
  m['C'] = 3;
  return m[c];
}
int main(void) {
  fgets(s, 100100, stdin);
  n = strlen(s);
  if (s[n - 1] == '\n') s[--n] = '\0';
  for (int i = 0; i < n; i++) s[i] = convert(s[i]);
  build();
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    char e[15];
    int type, c, l, r, len = 0;
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d", &l);
      while (!isalpha(c = getchar()))
        ;
      update(--l, convert(c));
    } else if (type == 2) {
      scanf("%d%d", &l, &r);
      while (!isalpha(c = getchar()))
        ;
      e[len++] = convert(c);
      while (isalpha(c = getchar())) e[len++] = convert(c);
      printf("%d\n", query(e, len, --l, --r));
    }
  }
  return 0;
}
