#include <bits/stdc++.h>
using namespace std;
int lsb(int x) { return x & -x; }
int tr(char ch) {
  if (ch == 'A') {
    return 0;
  }
  if (ch == 'T') {
    return 1;
  }
  if (ch == 'G') return 2;
  return 3;
}
const int N = 1e5 + 2;
int n;
int cnt[12][12][4][N];
void up(int pos, int val, int add) {
  for (int mod = 1; mod <= 10; ++mod) {
    int r = (pos) % mod;
    for (int i = pos + 1; i <= n; i += lsb(i)) {
      cnt[mod][r][val][i] += add;
    }
  }
}
int query(int l, int mod, int rest, int val) {
  int sol = 0;
  if (l == -1) return 0;
  for (int i = l + 1; i >= 1; i -= lsb(i)) sol += cnt[mod][rest][val][i];
  return sol;
}
int query(int l, int r, int mod, int rest, int val) {
  return query(r, mod, rest, val) - query(l - 1, mod, rest, val);
}
int main() {
  string s;
  cin >> s;
  n = s.size();
  int q;
  cin >> q;
  for (int i = 0; i < n; ++i) {
    up(i, tr(s[i]), 1);
  }
  for (; q; --q) {
    int tip;
    cin >> tip;
    if (tip == 1) {
      int poz;
      char ch;
      cin >> poz >> ch;
      poz--;
      up(poz, tr(s[poz]), -1);
      up(poz, tr(ch), 1);
      s[poz] = ch;
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      string act;
      cin >> act;
      act.resize(min((int)act.size(), r - l + 1));
      int sol = 0;
      int rest = l % act.size();
      for (int i = 0; i < act.size(); ++i) {
        sol += query(l, r, act.size(), rest, tr(act[i]));
        rest = (rest + 1) % act.size();
      }
      cout << sol << '\n';
    }
  }
}
