#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
int fw[N][4][11][10];
void add(int p, int c, int k) {
  for (int i = 1; i <= 10; ++i) {
    for (int j = p; j < N; j += j & -j) {
      fw[j][c][i][p % i] += k;
    }
  }
}
int get(int p, int c, int it, int len) {
  if (p == 0) return 0;
  int res = 0;
  for (int i = p; i; i -= i & -i) {
    res += fw[i][c][len][it % len];
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int n = s.size();
  vector<int> id(300);
  id['A'] = 0;
  id['T'] = 1;
  id['G'] = 2;
  id['C'] = 3;
  for (int i = 0; i < n; ++i) {
    add(i + 1, id[s[i]], 1);
  }
  int q;
  cin >> q;
  while (q--) {
    int t1;
    cin >> t1;
    if (t1 == 1) {
      int pos;
      char c;
      cin >> pos >> c;
      add(pos, id[s[pos - 1]], -1);
      s[pos - 1] = c;
      add(pos, id[s[pos - 1]], 1);
    } else {
      string z;
      int l, r;
      cin >> l >> r >> z;
      int len = z.size();
      int cnt = 0;
      for (int i = 0; i < len; ++i) {
        cnt += get(r, id[z[i]], l + i, len) - get(l - 1, id[z[i]], l + i, len);
      }
      cout << cnt << '\n';
    }
  }
}
