#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int node[4][11][11][maxn];
int h[110];
char s[maxn], e[11];
int lowbit(int x) { return x & (-x); }
void add(int ty, int pos, int x, int d) {
  for (; x < maxn; x += lowbit(x)) {
    for (int k = 1; k <= 10; k++) {
      node[ty][k][pos % k][x] += d;
    }
  }
}
int sum(int ty, int len, int pos, int x) {
  int ans = 0;
  for (; x > 0; x -= lowbit(x)) {
    ans += node[ty][len][pos][x];
  }
  return ans;
}
int query(int l, int r, int ty, int len, int pos) {
  return sum(ty, len, pos, r) - sum(ty, len, pos, l - 1);
}
int main() {
  int n;
  h['A'] = 0;
  h['T'] = 1;
  h['C'] = 2;
  h['G'] = 3;
  scanf("%s%d", s, &n);
  int len = strlen(s);
  for (int i = 0; i < len; i++) {
    add(h[s[i]], i, i + 1, 1);
  }
  while (n--) {
    int a, b, c;
    scanf("%d", &a);
    if (a == 1) {
      scanf("%d%s", &b, e);
      add(h[s[b - 1]], b - 1, b, -1);
      add(h[e[0]], b - 1, b, 1);
      s[b - 1] = e[0];
    } else {
      scanf("%d%d%s", &b, &c, e);
      len = strlen(e);
      int ans = 0;
      for (int i = 0; i < len; i++) {
        ans += query(b, c, h[e[i]], len, (i + b - 1) % len);
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
