#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int E = 11;
int n, id[300], t[E][E][4][N];
char s[N], p[E];
void upd(int t[], int u, int x) {
  for (int i = u; i <= n; i += i & -i) t[i] += x;
}
int get(int t[], int u) {
  int ret = 0;
  for (int i = u; i; i -= i & -i) ret += t[i];
  return ret;
}
int main() {
  id['A'] = 0, id['T'] = 1, id['C'] = 2, id['G'] = 3;
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j < E; j++) upd(t[j][i % j][id[s[i]]], i, 1);
  int q;
  scanf("%d", &q);
  while (q--) {
    int ty;
    scanf("%d", &ty);
    if (ty == 1) {
      int pos;
      scanf("%d%s", &pos, p);
      for (int i = 1; i < E; i++) upd(t[i][pos % i][id[s[pos]]], pos, -1);
      s[pos] = p[0];
      for (int i = 1; i < E; i++) upd(t[i][pos % i][id[s[pos]]], pos, 1);
    } else {
      int l, r;
      scanf("%d%d%s", &l, &r, p);
      int len = strlen(p);
      int ans = 0;
      for (int i = 0; i < len; i++)
        ans += get(t[len][(l + i) % len][id[p[i]]], r) -
               get(t[len][(l + i) % len][id[p[i]]], l - 1);
      printf("%d\n", ans);
    }
  }
  return 0;
}
