#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
char s[maxn];
int bit[4][11][10][maxn];
void add(int a, int pos, int i, int v) {
  while (i < maxn) {
    for (int len = 1; len <= 10; len++) bit[a][len][pos % len][i] += v;
    i += i & -i;
  }
}
int sum(int a, int pos, int len, int i) {
  int ret = 0;
  while (i > 0) {
    ret += bit[a][len][pos][i];
    i -= i & -i;
  }
  return ret;
}
char dic[100];
int main() {
  scanf("%s", s);
  dic['A'] = 0;
  dic['T'] = 1;
  dic['G'] = 2;
  dic['C'] = 3;
  for (int i = 0; i < strlen(s); i++) {
    int a = dic[s[i]];
    add(a, i, i + 1, 1);
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int op, l, r, a, ba;
    char tmp[15];
    scanf("%d", &op);
    if (op & 1) {
      scanf("%d%s", &l, tmp);
      a = dic[tmp[0]];
      ba = dic[s[l - 1]];
      if (ba == a) continue;
      add(ba, l - 1, l, -1);
      add(a, l - 1, l, 1);
      s[l - 1] = tmp[0];
    } else {
      scanf("%d%d%s", &l, &r, tmp);
      int len = strlen(tmp), pos;
      int ans = 0;
      for (int i = 0; i < len; i++) {
        a = dic[tmp[i]];
        pos = (i + l - 1) % len;
        ans += sum(a, pos, len, r) - sum(a, pos, len, l - 1);
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
