#include <bits/stdc++.h>
using namespace std;
void io() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(15);
}
const int MAXN = 1e5 + 3;
int BIT[4][12][12][MAXN];
void update(int *BIT, int idx, int val) {
  assert(idx > 0);
  while (idx < MAXN) {
    BIT[idx] += val;
    idx += (idx & -idx);
  }
}
int query(int *BIT, int idx) {
  int ret = 0;
  while (idx > 0) {
    ret += BIT[idx];
    idx -= (idx & -idx);
  }
  return ret;
}
void pointUpdate(int *BIT, int idx, int val) {
  idx++;
  update(BIT, idx, val);
}
int rangeQuery(int *BIT, int l, int r) {
  l++;
  r++;
  int ret = query(BIT, r);
  if (l > 1) {
    ret = ret - query(BIT, l - 1);
  }
  return ret;
}
int get_val(char ch) {
  if (ch == 'A') return 0;
  if (ch == 'G') return 1;
  if (ch == 'C') return 2;
  if (ch == 'T') return 3;
}
int main(int argc, char *argv[]) {
  io();
  string s;
  string e;
  cin >> s;
  int q, typ;
  int n = s.length();
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= 10; j++) {
      pointUpdate(BIT[get_val(s[i])][j][i % j], i, 1);
    }
  }
  cin >> q;
  while (q--) {
    cin >> typ;
    if (typ == 1) {
      int x;
      char ch;
      cin >> x >> ch;
      x--;
      for (int j = 1; j <= 10; j++) {
        pointUpdate(BIT[get_val(s[x])][j][x % j], x, -1);
        pointUpdate(BIT[get_val(ch)][j][x % j], x, 1);
      }
      s[x] = ch;
    } else {
      int l, r;
      cin >> l >> r >> e;
      l--;
      r--;
      int len = e.length();
      int fans = 0;
      for (int i = 0; i < len; i++) {
        fans = fans + rangeQuery(BIT[get_val(e[i])][len][(l + i) % len], l, r);
      }
      cout << fans << '\n';
    }
  }
  return 0;
}
