#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int data[12][12][4][N];
int n;
int lowbit(int x) { return x & (-x); }
void add(int x, int dt, int *c) {
  for (; x <= n; x += lowbit(x)) c[x] += dt;
}
int query(int x, int *c) {
  int sum = 0;
  for (int i = x; i; i -= lowbit(i)) sum += c[i];
  return sum;
}
int which(char c) {
  switch (c) {
    case 'T':
      return 0;
    case 'A':
      return 1;
    case 'C':
      return 2;
    case 'G':
      return 3;
  }
}
char s[N];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 10; j++) {
      add(i, 1, data[j][i % j][which(s[i])]);
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      int pos;
      char c[2];
      scanf("%d%s", &pos, c);
      for (int j = 1; j <= 10; j++) {
        add(pos, -1, data[j][pos % j][which(s[pos])]);
      }
      s[pos] = c[0];
      for (int j = 1; j <= 10; j++) {
        add(pos, 1, data[j][pos % j][which(s[pos])]);
      }
    } else {
      int l, r;
      char c[15];
      scanf("%d%d%s", &l, &r, c);
      int len = strlen(c);
      int pos = l % len;
      int ans = 0;
      for (int j = 0; j < len; j++) {
        ans += query(r, data[len][(pos + j) % len][which(c[j])]) -
               query(l - 1, data[len][(pos + j) % len][which(c[j])]);
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
