#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 10;
int n, m, q;
int sum[11][11][4][mx], lens;
char str[mx], c[20];
inline int lowbit(int x) { return x & (-x); }
int getnum(char c1) {
  switch (c1) {
    case 'A':
      return 0;
    case 'T':
      return 1;
    case 'G':
      return 2;
    case 'C':
      return 3;
  }
}
void add(int s, int x, int y, int z, int v) {
  for (int i = s; i <= lens; i += lowbit(i)) sum[x][y][z][i] += v;
}
void update(int x, int k, int v) {
  for (int j = 1; j <= 10; j++) {
    int p = x % j;
    if (!p) p = j;
    add(x, p, j, k, v);
  }
}
int query(int x, int y, int k, int s) {
  int ans = 0;
  while (s) {
    ans += sum[x][y][k][s];
    s -= lowbit(s);
  }
  return ans;
}
int main() {
  while (~scanf("%s", str + 1)) {
    memset(sum, 0, sizeof(sum));
    scanf("%d", &n);
    lens = strlen(str + 1);
    for (int i = 1; i <= lens; i++) {
      int k = getnum(str[i]);
      update(i, k, 1);
    }
    int x, y, z;
    while (n--) {
      scanf("%d", &x);
      if (x == 1) {
        scanf("%d%s", &y, c);
        update(y, getnum(str[y]), -1);
        update(y, getnum(c[0]), 1);
        str[y] = c[0];
      } else {
        scanf("%d%d%s", &y, &z, c);
        int len = strlen(c), ans = 0;
        for (int i = 0; i < len; i++) {
          int p = (i + y) % len;
          if (!p) p = len;
          ans += query(p, len, getnum(c[i]), z) -
                 query(p, len, getnum(c[i]), y - 1);
        }
        printf("%d\n", ans);
      }
    }
  }
  return 0;
}
