#include <bits/stdc++.h>
using namespace std;
struct fenwick {
  vector<int> bit;
  int n;
  fenwick(int n_) : n(n_) { bit.assign(n, 0); }
  int sum(int r) {
    int ret = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1) ret += bit[r];
    return ret;
  }
  int sum(int l, int r) { return sum(r) - sum(l - 1); }
  void add(int idx, int delta) {
    for (; idx < n; idx = idx | (idx + 1)) bit[idx] += delta;
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  int n = (int)s.size();
  vector<vector<vector<fenwick>>> dp(
      4, vector<vector<fenwick>>(11, vector<fenwick>(10, fenwick(n))));
  vector<int> idx(256);
  idx['A'] = 0;
  idx['T'] = 1;
  idx['G'] = 2;
  idx['C'] = 3;
  for (int i = 0; i < n; ++i) {
    for (int t = 1; t <= 10; ++t) {
      for (int offset = 0; offset < t; ++offset) {
        if (i % t == offset) {
          dp[idx[s[i]]][t][offset].add(i, +1);
        }
      }
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int x;
      char c;
      cin >> x >> c;
      --x;
      for (int t = 1; t <= 10; ++t) {
        for (int offset = 0; offset < t; ++offset) {
          if (x % t == offset) {
            dp[idx[s[x]]][t][offset].add(x, -1);
            dp[idx[c]][t][offset].add(x, +1);
          }
        }
      }
      s[x] = c;
    } else {
      int l, r;
      string e;
      cin >> l >> r >> e;
      --l;
      --r;
      int ans = 0;
      int t = (int)e.size(), x = l % t;
      for (int offset = 0; offset < t; ++offset) {
        ans += dp[idx[e[offset]]][t][(offset + x) % t].sum(l, r);
      }
      cout << ans << '\n';
    }
  }
}
