#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T abs(T x) {
  return x < 0 ? -x : x;
}
const int MAXLEN = 10;
void Add(vector<int>& fen, int pos, int val) {
  for (int x = pos; x < ((int)(fen).size()); x = (x | (x + 1))) {
    fen[x] += val;
  }
}
int Sum(const vector<int>& fen, int pos) {
  int res = 0;
  for (int x = pos; x >= 0; x = (x & (x + 1)) - 1) {
    res += fen[x];
  }
  return res;
}
const string S = "ATGC";
int ToInt(char c) {
  for (int i = 0; i < 4; ++i) {
    if (S[i] == c) {
      return i;
    }
  }
  return -1;
}
int main() {
  ios_base::sync_with_stdio(0);
  string s;
  cin >> s;
  int n = ((int)(s).size());
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    a[i] = ToInt(s[i]);
  }
  vector<vector<vector<vector<int>>>> fen(MAXLEN + 1);
  for (int i = 1; i <= MAXLEN; ++i) {
    fen[i].resize(i);
    for (int j = 0; j < i; ++j) {
      fen[i][j].resize(4);
      for (int t = 0; t < 4; ++t) {
        fen[i][j][t].resize(n / i + 5);
      }
    }
  }
  for (int len = 1; len <= MAXLEN; ++len) {
    for (int i = 0; i < n; ++i) {
      Add(fen[len][i % len][a[i]], i / len, 1);
    }
  }
  int m;
  cin >> m;
  vector<int> cur(MAXLEN);
  for (int i = 0; i < m; ++i) {
    int type;
    cin >> type;
    if (type == 1) {
      int pos;
      char c;
      cin >> pos >> c;
      --pos;
      int val = ToInt(c);
      for (int len = 1; len <= MAXLEN; ++len) {
        Add(fen[len][pos % len][a[pos]], pos / len, -1);
        Add(fen[len][pos % len][val], pos / len, 1);
      }
      a[pos] = val;
    } else {
      int l, r;
      string cur_s;
      cin >> l >> r >> cur_s;
      --l, --r;
      int len = ((int)(cur_s).size());
      for (int j = 0; j < len; ++j) {
        cur[(l + j) % len] = ToInt(cur_s[j]);
      }
      int res = 0;
      for (int j = 0; j < len; ++j) {
        int rr = (r + len - j) / len - 1;
        int ll = (l + len - j - 1) / len;
        res += Sum(fen[len][j][cur[j]], rr) - Sum(fen[len][j][cur[j]], ll - 1);
      }
      cout << res << "\n";
    }
  }
  return 0;
}
