#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const int MOD = 1000 * 1000 * 1000 + 7;
const long long LINF = INF * (long long)INF;
const int MAX = 100 * 1000 + 7;
int f[MAX][11][11][4];
void u(int x, int A, int B, int C, int v) {
  for (; x < MAX; x += (x & (-x))) f[x][A][B][C] += v;
}
int g(int x, int A, int B, int C) {
  int res = 0;
  for (; x; x -= x & (-x)) res += f[x][A][B][C];
  return res;
}
int M(char c) {
  if (c == 'A') return 0;
  if (c == 'C') return 1;
  if (c == 'T') return 2;
  return 3;
}
int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.size();
  for (int i = (0); i < (n); i++) {
    for (int j = (1); j < (11); j++) {
      u(i + 1, j, (i + 1) % j, M(s[i]), 1);
    }
  }
  int q;
  cin >> q;
  string e;
  for (int qq = (0); qq < (q); qq++) {
    int t;
    cin >> t;
    if (t == 1) {
      int p;
      char c;
      cin >> p >> c;
      for (int j = (1); j < (11); j++) {
        u(p, j, p % j, M(s[p - 1]), -1);
      }
      s[p - 1] = c;
      for (int j = (1); j < (11); j++) {
        u(p, j, p % j, M(s[p - 1]), 1);
      }
    } else {
      int l, r;
      cin >> l >> r >> e;
      int m = (int)e.size();
      int res = 0;
      for (int i = (0); i < (m); i++) {
        int pos = (l + i) % m;
        res += g(r, m, pos, M(e[i]));
        res -= g(l - 1, m, pos, M(e[i]));
      }
      cout << res << endl;
    }
  }
  return 0;
}
