#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using vb = vector<bool>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
struct Bit {
  vl bit;
  int n;
  Bit(int nn) : n(nn), bit(vl(nn + 2, 0)) {}
  void add(int i, ll v) {
    for (++i; i <= n + 1; i += i & -i) bit[i] += v;
  }
  ll get_cumulative(int i) {
    ll res = 0;
    for (++i; i; i -= i & -i) res += bit[i];
    return res;
  }
  ll get_interval(int a, int b) {
    return get_cumulative(b) - get_cumulative(a - 1);
  }
};
int g(char c) {
  if (c == 'A') return 0;
  if (c == 'T') return 1;
  if (c == 'G') return 2;
  return 3;
}
ll count(Bit& b, int l, int r) { return b.get_interval(l, r); }
vector<vector<vector<Bit>>> bs;
Bit& getBit(int base, int offset, int skip) { return bs[base][offset][skip]; }
void set(Bit& b, int idx) { b.add(idx, 1); }
void unset(Bit& b, int idx) { b.add(idx, -1); }
int main() {
  string s;
  cin >> s;
  bs = vector<vector<vector<Bit>>>(
      4, vector<vector<Bit>>(11, vector<Bit>(11, Bit(s.size()))));
  int q;
  cin >> q;
  for (int i = (0); i < (s.size()); i++) {
    int neu = g(s[i]);
    for (int off = (0); off < (11); off++) {
      for (int skip = (1); skip < (11); skip++) {
        if (i % skip == off) {
          getBit(neu, off, skip).add(i, 1);
        }
      }
    }
  }
  for (int qq = (0); qq < (q); qq++) {
    int t;
    cin >> t;
    if (t == 1) {
      int x;
      char c;
      cin >> x >> c;
      x--;
      int old = g(s[x]);
      int neu = g(c);
      for (int off = (0); off < (11); off++) {
        for (int skip = (1); skip < (11); skip++) {
          if (x % skip == off) {
            getBit(old, off, skip).add(x, -1);
            getBit(neu, off, skip).add(x, 1);
          }
        }
      }
      s[x] = c;
    } else {
      int l, r;
      string e;
      cin >> l >> r >> e;
      l--;
      r--;
      ll sum = 0;
      for (int i = (0); i < (e.size()); i++) {
        ll gr = count(getBit(g(e[i]), (l + i) % e.size(), e.size()), l, r);
        sum += gr;
      }
      cout << sum << endl;
    }
  }
}
