#include <bits/stdc++.h>
using namespace std;
vector<int> build(vector<int>& a) {
  int n = (int)a.size();
  int _n = 1;
  while (_n < n) {
    _n *= 2;
  }
  n = _n;
  a.resize(n, 0);
  vector<int> tree(2 * n);
  for (int i = 2 * n - 1; i >= 0; i--) {
    if (i >= n) {
      tree[i] = a[i - n];
    } else {
      tree[i] = tree[2 * i] + tree[2 * i + 1];
    }
  }
  return tree;
}
void update(int pos, int val, vector<int>& tree) {
  int n = (int)tree.size() / 2;
  int v = pos + n;
  tree[v] = val;
  while (v > 1) {
    v /= 2;
    tree[v] = tree[2 * v] + tree[2 * v + 1];
  }
}
int count(int v, int vl, int vr, int l, int r, vector<int>& tree) {
  if (vl >= r || vr <= l) {
    return 0;
  }
  if (vl >= l && vr <= r) {
    return tree[v];
  }
  int vm = (vl + vr) / 2;
  return count(2 * v, vl, vm, l, r, tree) +
         count(2 * v + 1, vm, vr, l, r, tree);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int n = (int)s.size();
  string alf = "ACGT";
  vector<vector<vector<vector<int> > > > a(10);
  for (int len = 0; len < 10; len++) {
    a[len].resize(len + 1, vector<vector<int> >(4));
    for (int pos = 0; pos <= len; pos++) {
      for (int x = pos; x < n; x += len + 1) {
        int num = alf.find(s[x]);
        for (int r = 0; r < 4; r++) {
          if (r == num)
            a[len][pos][r].push_back(1);
          else
            a[len][pos][r].push_back(0);
        }
      }
    }
  }
  vector<vector<vector<vector<int> > > > d(10);
  for (int len = 0; len < 10; len++) {
    d[len].resize(len + 1, vector<vector<int> >(4));
    for (int pos = 0; pos <= len; pos++) {
      for (int r = 0; r < 4; r++) {
        d[len][pos][r] = build(a[len][pos][r]);
      }
    }
  }
  int k;
  cin >> k;
  for (int z = 0; z < k; z++) {
    int t;
    cin >> t;
    if (t == 1) {
      int pos;
      char c;
      cin >> pos >> c;
      pos--;
      int old = alf.find(s[pos]);
      int num = alf.find(c);
      s[pos] = c;
      for (int len = 0; len < 10; len++) {
        for (int r = 0; r < 4; r++) {
          if (r == old) {
            update(pos / (len + 1), 0, d[len][pos % (len + 1)][r]);
          }
          if (r == num) {
            update(pos / (len + 1), 1, d[len][pos % (len + 1)][r]);
          }
        }
      }
    } else {
      int l, r;
      string t;
      cin >> l >> r >> t;
      l--;
      r--;
      int len = (int)t.size();
      int sum = 0;
      for (int pos = 0; pos < min(len, r - l + 1); pos++) {
        int c = alf.find(t[pos]);
        int sh = (pos + l) % len;
        int left = (pos + l) / len;
        int right = (r - l - pos) / len + left + 1;
        sum += count(1, 0, (int)d[len - 1][sh][c].size() / 2, left, right,
                     d[len - 1][sh][c]);
      }
      cout << sum << endl;
    }
  }
  return 0;
}
