#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int n;
int dic[200];
int t[4][11][10][MAXN];
char a[MAXN], q[11];
int Read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x * 10) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
void Put1(int x) {
  if (x > 9) Put1(x / 10);
  putchar(x % 10 ^ 48);
}
void Put(int x, char c = -1) {
  if (x < 0) putchar('-'), x = -x;
  Put1(x);
  if (c >= 0) putchar(c);
}
template <typename T>
T Max(T x, T y) {
  return x > y ? x : y;
}
template <typename T>
T Min(T x, T y) {
  return x < y ? x : y;
}
template <typename T>
T Abs(T x) {
  return x < 0 ? -x : x;
}
void pre() {
  dic['A'] = 0;
  dic['T'] = 1;
  dic['G'] = 2;
  dic['C'] = 3;
}
int lowbit(int x) { return x & -x; }
void Add(int x, int w, int c, int y, int ad) {
  for (int i = x; i <= n; i += lowbit(i)) t[w][c][y][i] += ad;
}
void Sadd(int x, int w, int ad) {
  for (int i = 1; i <= 10; ++i) Add(x, w, i, x % i, ad);
}
int Sum(int x, int w, int c, int y) {
  int ret = 0;
  for (int i = x; i >= 1; i -= lowbit(i)) ret += t[w][c][y][i];
  return ret;
}
char gc() {
  char c = getchar();
  while (c > 'Z' || c < 'A') c = getchar();
  return c;
}
int main() {
  pre();
  scanf("%s", a + 1);
  n = strlen(a + 1);
  for (int i = 1; i <= n; ++i) Sadd(i, dic[(int)a[i]], 1);
  for (int Q = Read(); Q; --Q) {
    int opt = Read();
    if (opt == 1) {
      int x = Read();
      Sadd(x, dic[(int)a[x]], -1);
      a[x] = gc();
      Sadd(x, dic[(int)a[x]], 1);
    } else {
      int l = Read(), r = Read();
      scanf("%s", q);
      int lenq = strlen(q), ans = 0;
      for (int i = 0; i < lenq && r - l >= i; ++i)
        ans += Sum(r, dic[(int)q[i]], lenq, (l + i) % lenq) -
               Sum(l - 1, dic[(int)q[i]], lenq, (l + i) % lenq);
      Put(ans, '\n');
    }
  }
  return 0;
}
