#include <bits/stdc++.h>
using namespace std;
int n, q;
char s[100002], a[11];
int pos[11][11 - 1][4][100002];
void add(int len, int r, int val, int x) {
  for (int i = abs(x); i <= n; i += i & (-i))
    if (x > 0)
      ++pos[len][r][val][i];
    else
      --pos[len][r][val][i];
}
int sum(int len, int r, int val, int x) {
  if (x <= 0) return 0;
  int ret = 0;
  for (; x > 0; x -= x & (-x)) ret += pos[len][r][val][x];
  return ret;
}
int conv(char c) {
  if (c == 'G') return 1;
  if (c == 'T') return 2;
  if (c == 'C') return 3;
  return 0;
}
int main() {
  scanf("%s\n", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) {
    int val = conv(s[i]);
    for (int len = 1; len <= 10; ++len) add(len, i % len, val, i);
  }
  scanf("%d", &q);
  while (q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int x, val1, val2;
      char c;
      scanf("%d %c", &x, &c);
      val1 = conv(s[x]);
      val2 = conv(c);
      if (val1 != val2) {
        for (int len = 1; len <= 10; ++len) {
          add(len, x % len, val2, x);
          add(len, x % len, val1, -x);
        }
        s[x] = c;
      }
    } else {
      int l, r, ans = 0;
      scanf("%d %d %s", &l, &r, a + 1);
      int len = strlen(a + 1);
      for (int i = l; i <= r && i < l + len; ++i) {
        int val = conv(a[i - l + 1]);
        ans += sum(len, i % len, val, r) - sum(len, i % len, val, l - 1);
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
