#include <bits/stdc++.h>
using namespace std;
const int lim = 1e5 + 5;
int n, q, bit[lim][55][4], f[10];
string a, b;
inline int conv(const char &k) {
  switch (k) {
    case 'A':
      return 0;
    case 'T':
      return 1;
    case 'G':
      return 2;
    case 'C':
      return 3;
  }
}
void update(int i, const int &j, const int &k, const int &v) {
  while (i <= n) {
    bit[i][j][k] += v;
    i += i & (-i);
  }
}
int get_sum(int i, int j, int k) {
  int ans = 0;
  while (i) {
    ans += bit[i][j][k];
    i -= i & (-i);
  }
  return ans;
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(0);
  memset(bit, 0, sizeof(bit));
  f[0] = 0;
  for (int i = 1; i < 10; ++i) f[i] = f[i - 1] + i;
  cin >> a >> q;
  n = a.length();
  for (int i = 0; i < n; ++i)
    for (int j = 1; j <= 10; ++j)
      update(i + 1, f[j - 1] + i % j, conv(a[i]), 1);
  while (q--) {
    int c, l, r, i;
    char x;
    cin >> c;
    if (c == 1) {
      cin >> i >> x;
      --i;
      for (int j = 1; j <= 10; ++j)
        update(i + 1, f[j - 1] + i % j, conv(a[i]), -1);
      a[i] = x;
      for (int j = 1; j <= 10; ++j)
        update(i + 1, f[j - 1] + i % j, conv(a[i]), 1);
    } else {
      cin >> l >> r >> b;
      --l;
      int ans = 0, m = b.length();
      for (int i = 0; i < m; ++i) {
        ans += get_sum(r, f[m - 1] + (l + i) % m, conv(b[i]));
        ans -= get_sum(l, f[m - 1] + (l + i) % m, conv(b[i]));
      }
      cout << ans << '\n';
    }
  }
}
