#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int num[200];
char let[4];
const int MAXN = (int)1e+5 + 5;
int fen[11][11][4][MAXN];
void call() {
  num['A'] = 0;
  num['C'] = 1;
  num['G'] = 2;
  num['T'] = 3;
  let[0] = 'A';
  let[1] = 'C';
  let[2] = 'G';
  let[3] = 'T';
}
void add(int k, int b, int z, int x, int d) {
  for (int i = x; i < MAXN; i |= (i + 1)) fen[k][b][z][i] += d;
}
int pref(int k, int b, int z, int x) {
  int res = 0;
  for (int i = x; i > 0; i = (i & (i + 1)) - 1) res += fen[k][b][z][i];
  return res;
}
int get(int k, int b, int z, int l, int r) {
  if (l > r) return 0;
  return pref(k, b, z, r) - pref(k, b, z, l - 1);
}
int main() {
  srand(time(NULL));
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  call();
  string s;
  cin >> s;
  int n = (int)s.size();
  s = "$" + s;
  for (int k = 1; k <= 10; k++) {
    for (int b = 1; b <= k; b++) {
      for (int z = 0; z < 4; z++) {
        for (int i = b; i <= n; i += k) {
          if (s[i] == let[z]) add(k, b, z, i, 1);
        }
      }
    }
  }
  int q;
  cin >> q;
  for (; q > 0; q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int pos;
      char c;
      cin >> pos >> c;
      for (int k = 1; k <= 10; k++) {
        int w = pos % k;
        if (w == 0) w = k;
        add(k, w, num[s[pos]], pos, -1);
        add(k, w, num[c], pos, 1);
      }
      s[pos] = c;
    } else {
      int l, r;
      cin >> l >> r;
      string now;
      cin >> now;
      int len = (int)now.size();
      int ans = 0, ptr = l % len;
      if (ptr == 0) ptr = len;
      for (int i = 0; i < len; i++) {
        ans += get(len, ptr, num[now[i]], l, r);
        ptr++;
        if (ptr > len) ptr = 1;
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
