#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int N = 100005;
struct Node {
  int cnt[11][10];
  Node() { memset(cnt, 0, sizeof cnt); }
} BIT[4][N];
int n;
char s[N];
string g = "ATGC";
int getID[500];
void edit(Node &a, int &v, int &p) {
  for (int i = 1; i <= 10; i++) a.cnt[i][(p - 1) % i] += v;
}
void upd(int pos, int val, int ind) {
  for (int i = pos; i <= n; i += i & (-i)) edit(BIT[ind][i], val, pos);
}
int getSum(int &ind, int id, int &len, int &mod) {
  int ret = 0;
  for (int i = id; i; i -= i & (-i)) ret += BIT[ind][i].cnt[len][mod];
  return ret;
}
int query(int &s, int &e, int &ind, int &len, int &mod) {
  return getSum(ind, e, len, mod) - getSum(ind, s, len, mod);
}
int q;
char f[12];
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < 4; i++) getID[g[i]] = i;
  for (int i = 0; i < n; i++) upd(i + 1, 1, getID[s[i]]);
  scanf("%d", &q);
  while (q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int x;
      char c;
      scanf("%d %c", &x, &c);
      upd(x, -1, getID[s[x - 1]]);
      s[x - 1] = c;
      upd(x, 1, getID[c]);
    } else {
      int l, r;
      scanf("%d %d %s", &l, &r, f);
      int ans = 0;
      int Len = strlen(f);
      --l;
      for (int i = 0, m = l % Len; i < Len; i++, m = (m + 1) % Len)
        ans += query(l, r, getID[f[i]], Len, m);
      printf("%d\n", ans);
    }
  }
  return 0;
}
