#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
char C[256];
string S;
int N, Q;
int BIT[MAXN][56][4];
void add(int idx, int mod, int c, int val) {
  for (; idx < MAXN; idx += idx & -idx) BIT[idx][mod][c] += val;
}
int get(int idx, int mod, int c) {
  int ret = 0;
  for (; idx > 0; idx -= idx & -idx) ret += BIT[idx][mod][c];
  return ret;
}
void update(int pos, int val) {
  for (int i = 1; i <= 10; i++)
    add(pos + 1, i * (i - 1) / 2 + pos % i, C[S[pos]], val);
}
int main() {
  ios::sync_with_stdio(0);
  C['A'] = 0;
  C['T'] = 1;
  C['G'] = 2;
  C['C'] = 3;
  cin >> S;
  N = S.size();
  for (int i = 0; i < N; i++) update(i, 1);
  cin >> Q;
  for (int i = 0, type; i < Q; i++) {
    cin >> type;
    if (type == 1) {
      int pos;
      char ch;
      cin >> pos >> ch;
      pos--;
      update(pos, -1);
      S[pos] = ch;
      update(pos, 1);
    } else {
      int ql, qr;
      string s;
      cin >> ql >> qr >> s;
      int len = s.size(), ans = 0;
      for (int j = 0; j < len; j++) {
        int mod = len * (len - 1) / 2 + (ql - 1 + j) % len;
        ans += get(qr, mod, C[s[j]]) - get(ql - 1, mod, C[s[j]]);
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
