#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
inline istream& operator>>(istream& fin, pair<T1, T2>& pr) {
  fin >> pr.first >> pr.second;
  return fin;
}
template <class T0, class T1, class T2>
inline istream& operator>>(istream& fin, tuple<T0, T1, T2>& t) {
  fin >> get<0>(t) >> get<1>(t) >> get<2>(t);
  return fin;
}
template <class T>
inline istream& operator>>(istream& fin, vector<T>& a) {
  for (auto& u : a) fin >> u;
  return fin;
}
template <class T, size_t n>
inline istream& operator>>(istream& fin, array<T, n>& a) {
  for (auto& u : a) fin >> u;
  return fin;
}
template <class FwdIter>
inline auto dump(FwdIter first, FwdIter last, const char* dlm = " ") -> void {
  copy(first, last,
       ostream_iterator<typename iterator_traits<FwdIter>::value_type>(cout,
                                                                       dlm));
}
template <typename T>
vector<T>& operator--(vector<T>& a) {
  for (auto& i : a) --i;
  return a;
}
template <typename T>
inline void inc(size_t i, T val, vector<T>& fen) {
  for (const auto n = fen.size(); i < n; i += i & -i) fen[i] += val;
}
template <typename T>
inline T acc(size_t i, const vector<T>& fen) {
  T out = 0;
  for (; i; i -= i & -i) out += fen[i];
  return out;
}
void c827() {
  string str;
  size_t n;
  cin >> str >> n;
  const size_t size = str.size();
  vector<vector<vector<vector<int>>>> fen(10);
  for (size_t i = 0; i < 10; ++i)
    fen[i] = vector<vector<vector<int>>>(
        i + 1, vector<vector<int>>(4, vector<int>(size + 5)));
  for (size_t i = 0; i < str.size(); ++i) {
    const auto j = str[i] == 'A'   ? 0
                   : str[i] == 'T' ? 1
                   : str[i] == 'G' ? 2
                                   : 3;
    for (size_t k = 0; k < 10; ++k) inc(i + 1, 1, fen[k][i % (k + 1)][j]);
  }
  for (size_t op; n; --n) {
    cin >> op;
    if (op == 1) {
      size_t i;
      cin >> i;
      --i;
      {
        const auto j = str[i] == 'A'   ? 0
                       : str[i] == 'T' ? 1
                       : str[i] == 'G' ? 2
                                       : 3;
        for (size_t k = 0; k < 10; ++k) inc(i + 1, -1, fen[k][i % (k + 1)][j]);
      }
      cin >> str[i];
      {
        const auto j = str[i] == 'A'   ? 0
                       : str[i] == 'T' ? 1
                       : str[i] == 'G' ? 2
                                       : 3;
        for (size_t k = 0; k < 10; ++k) inc(i + 1, 1, fen[k][i % (k + 1)][j]);
      }
    } else {
      size_t l, r;
      string wrd;
      cin >> l >> r >> wrd;
      --l;
      size_t out = 0;
      const auto& f = fen[wrd.size() - 1];
      for (size_t k = 0; k < wrd.size(); ++k) {
        const auto j = wrd[k] == 'A'   ? 0
                       : wrd[k] == 'T' ? 1
                       : wrd[k] == 'G' ? 2
                                       : 3;
        out += acc(r, f[(k + l) % wrd.size()][j]) -
               acc(l, f[(k + l) % wrd.size()][j]);
      }
      cout << out << '\n';
    }
  }
}
int main(const int argc, char* argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  c827();
  return EXIT_SUCCESS;
}
