#include <bits/stdc++.h>
using namespace std;
int bitct(long long r) {
  int c = 0;
  for (; r; r &= r - 1) c++;
  return c;
}
long long gcd(long long x, long long y) { return x ? gcd(y % x, x) : y; }
long long choose(long long n, long long q) {
  if (n == 0 || q == 0) return 1;
  if (q == 1)
    return n;
  else
    return (choose(n, q - 1) * (n - q + 1) / q);
}
template <typename T>
ostream& operator<<(ostream& o, vector<T> v) {
  o << "[";
  int i = 0, s = v.size();
  for (; i + 1 < s; i++) o << v[i] << ", ";
  if (s) o << v[i];
  o << "]";
  return o;
}
template <typename K, typename V>
ostream& operator<<(ostream& o, unordered_map<K, V> m) {
  o << "{";
  for (auto i : m) o << i.first << " -> " << i.second << ", ";
  o << "}";
  return o;
}
template <typename K, typename V>
ostream& operator<<(ostream& o, map<K, V> m) {
  o << "{";
  for (auto i : m) o << i.first << " -> " << i.second << ", ";
  o << "}";
  return o;
}
template <typename K>
ostream& operator<<(ostream& o, set<K> m) {
  o << "{";
  for (auto i : m) o << i << ", ";
  o << "}";
  return o;
}
template <typename K>
ostream& operator<<(ostream& o, unordered_set<K> m) {
  o << "{";
  for (auto i : m) o << i << ", ";
  o << "}";
  return o;
}
template <typename T>
ostream& printv(vector<T> v) {
  int i = 0, s = v.size();
  for (; i + 1 < s; i++) cout << v[i] << " ";
  if (s) cout << v[i];
  return cout;
}
int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  long long th = 2000, tn = 50;
  map<char, int> dna{{'A', 0}, {'C', 1}, {'T', 2}, {'G', 3}};
  vector<vector<vector<vector<long long> > > > pres(
      1 + s.size() / tn,
      vector<vector<vector<long long> > >(
          10, vector<vector<long long> >(10, vector<long long>(4, 0))));
  for (int i = 0; i < pres.size(); i++) {
    for (int j = 0; j < tn && j < s.size() - i * tn; j++) {
      char me = s[tn * i + j];
      long long nme = dna[me];
      for (int k = 0; k < 10; k++) {
        long long span = k + 1;
        pres[i][k][j % span][nme]++;
      }
    }
  }
  vector<vector<vector<vector<long long> > > > pre(
      1 + s.size() / th,
      vector<vector<vector<long long> > >(
          10, vector<vector<long long> >(10, vector<long long>(4, 0))));
  for (int i = 0; i < pre.size(); i++) {
    for (int j = 0; j < th && j < s.size() - i * th; j++) {
      char me = s[th * i + j];
      long long nme = dna[me];
      for (int k = 0; k < 10; k++) {
        long long span = k + 1;
        pre[i][k][j % span][nme]++;
      }
    }
  }
  long long Q;
  cin >> Q;
  for (int q = 0; q < Q; q++) {
    long long type;
    cin >> type;
    if (1 == type) {
      long long x;
      string c;
      cin >> x >> c;
      x--;
      long long nme = dna[c[0]];
      long long oldnme = dna[s[x]];
      s[x] = c[0];
      for (int k = 0; k < 10; k++) {
        long long span = k + 1;
        pre[x / th][k][(x % th) % span][nme]++;
        pre[x / th][k][(x % th) % span][oldnme]--;
      }
      for (int k = 0; k < 10; k++) {
        long long span = k + 1;
        pres[x / tn][k][(x % tn) % span][nme]++;
        pres[x / tn][k][(x % tn) % span][oldnme]--;
      }
    } else {
      long long l, r;
      string e;
      cin >> l >> r >> e;
      l--, r--;
      vector<int> ee;
      for (char eee : e) ee.push_back(dna[eee]);
      long long match = 0;
      for (long long i = l; i <= r; i++) {
        if (i % th == 0 && r - i > th) {
          for (int k = 0; k < e.size(); k++)
            match += pre[i / th][e.size() - 1][k][ee[(i + k - l) % e.size()]];
          i += th - 1;
          continue;
        }
        if (i % tn == 0 && r - i > tn) {
          for (int k = 0; k < e.size(); k++)
            match += pres[i / tn][e.size() - 1][k][ee[(i + k - l) % e.size()]];
          i += tn - 1;
          continue;
        }
        if (e[(i - l) % e.size()] == s[i]) match++;
      }
      cout << match << endl;
    }
  }
}
