#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 113;
class Fenvick {
 public:
  Fenvick(int sz = 0) {
    size_ = sz;
    arr.assign(sz, 0);
  }
  void add(int ind, int val) {
    for (int i = ind; i < size_; i |= i + 1) {
      arr[i] += val;
    }
  }
  int rsq(int l, int r) {
    if (l > r) return 0;
    return rsq_(r) - rsq_(l - 1);
  }

 private:
  int size_;
  vector<int> arr;
  int rsq_(int r) {
    if (r < 0) return 0;
    int result = 0;
    for (int i = r; i >= 0; i = (i & (i + 1)) - 1) {
      result += arr[i];
    }
    return result;
  }
};
vector<Fenvick> tree[4][11];
void build(int n) {
  for (int mod = 1; mod <= 10; ++mod) {
    for (int t = 0; t < 4; ++t) {
      for (int i = 0; i < mod; ++i) {
        tree[t][mod].push_back(Fenvick((n + mod - 1) / mod));
      }
    }
  }
}
int ctoi(char c) {
  switch (c) {
    case 'A':
      return 0;
    case 'G':
      return 1;
    case 'T':
      return 2;
    case 'C':
      return 3;
  }
  exit(1);
}
string s;
int q, n;
int main() {
  cin >> s >> q;
  build(n = s.size());
  for (int i = 0; i < n; ++i) {
    int t = ctoi(s[i]);
    for (int mod = 1; mod <= 10; ++mod) {
      tree[t][mod][i % mod].add(i / mod, 1);
    }
  }
  for (int i = 0; i < q; ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      int x;
      char c;
      cin >> x >> c;
      --x;
      for (int mod = 1; mod <= 10; ++mod) {
        tree[ctoi(s[x])][mod][x % mod].add(x / mod, -1);
        tree[ctoi(c)][mod][x % mod].add(x / mod, 1);
      }
      s[x] = c;
      continue;
    }
    int l, r, result = 0;
    string e;
    cin >> l >> r >> e;
    --l, --r;
    for (int j = 0; j < e.size(); ++j) {
      int ll, rr, ost;
      ost = (l + j) % e.size();
      ll = (l - ost + e.size() - 1) / e.size();
      rr = (r - ost < 0) ? -1 : (r - ost) / (int)e.size();
      result += tree[ctoi(e[j])][e.size()][ost].rsq(ll, rr);
    }
    cout << result << endl;
  }
}
