#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
char s[maxn], op[12];
int n, q, t, x, l, r, bit[11][10][4][maxn], m;
inline int sum(int *bit, int x) {
  int ret = 0;
  while (x) {
    ret += bit[x];
    x -= x & -x;
  }
  return ret;
}
inline void update(int *bit, int x, int v) {
  while (x <= n) {
    bit[x] += v;
    x += x & -x;
  }
}
inline int id(char ch) {
  if (ch == 'A')
    return 0;
  else if (ch == 'T')
    return 1;
  else if (ch == 'C')
    return 2;
  return 3;
}
int main() {
  scanf("%s%d", s + 1, &q);
  n = strlen(s + 1);
  for (int i = 1; i <= n; ++i)
    for (int mod = 1; mod <= 10; ++mod)
      update(bit[mod][i % mod][id(s[i])], i, 1);
  while (q--) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d%s", &x, op);
      for (int mod = 1; mod <= 10; ++mod)
        update(bit[mod][x % mod][id(s[x])], x, -1);
      s[x] = op[0];
      for (int mod = 1; mod <= 10; ++mod)
        update(bit[mod][x % mod][id(s[x])], x, 1);
    } else {
      scanf("%d%d%s", &l, &r, op);
      m = strlen(op);
      int res = 0;
      for (int i = 0; i < m; ++i)
        res += (sum(bit[m][(i + l) % m][id(op[i])], r) -
                sum(bit[m][(i + l) % m][id(op[i])], l - 1));
      printf("%d\n", res);
    }
  }
  return 0;
}
