#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, q;
char s[maxn];
struct bit {
  int arr[maxn];
  void init() {
    for (int i = 0; i <= n; ++i) arr[i] = 0;
  }
  void add(int idx, int val) {
    ++idx;
    while (idx <= n) {
      arr[idx] += val;
      idx += (idx & -idx);
    }
  }
  int get(int idx) {
    ++idx;
    int sum = 0;
    while (idx > 0) {
      sum += arr[idx];
      idx -= (idx & -idx);
    }
    return sum;
  }
  int query(int l, int r) { return get(r) - get(l - 1); }
};
unordered_map<char, int> id;
bit pre[11][11][4];
void compute() {
  id['A'] = 0;
  id['T'] = 1;
  id['G'] = 2;
  id['C'] = 3;
  fprintf(stderr, "compute()\n");
  for (int mod = 1; mod <= 10; ++mod) {
    for (int m = 0; m < mod; ++m)
      for (int k = 0; k < 4; ++k) pre[mod][m][k].init();
    for (int i = 0; i < n; ++i) pre[mod][i % mod][id[s[i]]].add(i, +1);
  }
}
int main() {
  scanf(" %s %d", s, &q);
  n = strlen(s);
  compute();
  fprintf(stderr, "queries\n");
  while (q--) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int x;
      char c;
      scanf("%d %c", &x, &c);
      --x;
      for (int mod = 1; mod <= 10; ++mod) {
        pre[mod][x % mod][id[s[x]]].add(x, -1);
        pre[mod][x % mod][id[c]].add(x, +1);
      }
      s[x] = c;
    }
    if (type == 2) {
      int l, r;
      char e[15];
      scanf("%d %d %s", &l, &r, e);
      int ans = 0;
      int mod = strlen(e);
      --l, --r;
      for (int i = 0, pos = l; i < mod; ++i, ++pos)
        ans += pre[mod][pos % mod][id[e[i]]].query(l, r);
      printf("%d\n", ans);
    }
  }
  return 0;
}
