#include <bits/stdc++.h>
using namespace std;
const int N = 101000;
int n, m;
int k[5][11][11][N], has[128];
char s[N];
inline int lowbit(int x) { return x & (-x); }
inline void add(int p, int c, int v) {
  for (int x = p; x <= n; x += lowbit(x))
    for (int j = 1; j <= 10; j++) k[c][j][p % j][x] += v;
}
inline int find(int c, int len, int mo, int x) {
  int ret = 0;
  while (x) {
    ret += k[c][len][mo][x];
    x -= lowbit(x);
  }
  return ret;
}
inline int query(int c, int len, int mo, int l, int r) {
  return find(c, len, mo, r) - find(c, len, mo, l - 1);
}
int main() {
  has['A' - '0'] = 0, has['T' - '0'] = 1, has['C' - '0'] = 2,
            has['G' - '0'] = 3;
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) add(i, has[s[i] - '0'], 1);
  scanf("%d", &m);
  char p[11];
  int ins, x, y;
  while (m--) {
    scanf("%d", &ins);
    if (ins == 1) {
      scanf("%d%s", &x, p);
      add(x, has[s[x] - '0'], -1);
      add(x, has[p[0] - '0'], 1);
      s[x] = p[0];
    } else {
      int ans = 0;
      scanf("%d%d%s", &x, &y, p);
      int len = strlen(p);
      for (int i = 0; i < len; i++)
        ans += query(has[p[i] - '0'], len, (i + x) % len, x, y);
      printf("%d\n", ans);
    }
  }
  return 0;
}
