#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
inline void writeln(int x) {
  char buffor[21];
  register int i = 0;
  int neg = 0;
  if (x < 0) {
    neg = 1;
    x = -x;
  }
  do {
    buffor[i++] = (x % 10) + '0';
    x /= 10;
  } while (x);
  i--;
  if (neg) putchar('-');
  while (i >= 0) putchar(buffor[i--]);
  putchar('\n');
}
int n, q, can;
int cnt[60][320][4], sum[11];
int inbl[60][100001];
string s;
void input() {
  cin >> s;
  n = s.size();
  s = " " + s;
  can = (int)sqrt(n);
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'A')
      s[i] = '0';
    else if (s[i] == 'C')
      s[i] = '1';
    else if (s[i] == 'G')
      s[i] = '2';
    else
      s[i] = '3';
  }
  for (int i = 1; i <= 10; i++) sum[i] = sum[i - 1] + i;
  for (int jump = 1; jump <= 10; jump++)
    for (int start = 1; start <= jump; start++) {
      int nowbl = sum[jump - 1] + start;
      int st = start;
      int cntbl = 0;
      int bl = 1;
      while (st <= n) {
        inbl[nowbl][st] = bl;
        cnt[nowbl][bl][(int)(s[st] - '0')]++;
        cntbl++;
        if (cntbl == can) {
          cntbl = 0;
          bl++;
        };
        st = st + jump;
      }
    }
}
void solve() {
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int typ;
    cin >> typ;
    if (typ == 1) {
      int x;
      char c;
      int cc;
      cin >> x;
      cin >> c;
      if (c == 'A')
        cc = 0;
      else if (c == 'C')
        cc = 1;
      else if (c == 'G')
        cc = 2;
      else
        cc = 3;
      int old = (int)(s[x] - '0');
      for (int tbl = 1; tbl <= 55; tbl++) {
        int tmp = inbl[tbl][x];
        if (tmp != 0) {
          cnt[tbl][tmp][old]--;
          cnt[tbl][tmp][cc]++;
        }
      }
      s[x] = (char)(cc + '0');
    } else {
      int l, r;
      string e;
      int m;
      cin >> l >> r;
      cin >> e;
      m = e.size();
      for (int j = 0; j <= m - 1; j++) {
        if (e[j] == 'A')
          e[j] = '0';
        else if (e[j] == 'C')
          e[j] = '1';
        else if (e[j] == 'G')
          e[j] = '2';
        else
          e[j] = '3';
      }
      int res = 0;
      for (int j = 0; j <= m - 1; j++) {
        int nowtyp = sum[m - 1] + ((l + j - 1) % m + 1);
        int ll = inbl[nowtyp][l + j] + 1;
        int st = l + j;
        while (st <= r and inbl[nowtyp][st] < ll) {
          if (s[st] == e[j]) res++;
          st = st + m;
        }
        while (r - st + 1 > can * m) {
          res += cnt[nowtyp][ll][(int)(e[j] - '0')];
          ll++;
          st += can * m;
        }
        while (st <= r) {
          if (s[st] == e[j]) res++;
          st = st + m;
        }
      }
      cout << res << '\n';
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  input();
  solve();
  return 0;
}
