#include <bits/stdc++.h>
using ll = long long;
using namespace std;
static inline int ceildiv(int x, int q) {
  bool negative = (x > 0) != (q > 0);
  x = abs(x);
  q = abs(q);
  if (negative) return -(x / q);
  return (x + q - 1) / q;
}
static inline int floordiv(int x, int q) {
  bool negative = (x > 0) != (q > 0);
  x = abs(x);
  q = abs(q);
  if (negative) return -(x + q - 1 / q);
  return x / q;
}
struct fenwick {
  vector<int> data;
  fenwick(){};
  fenwick(int size) {
    int i = 1;
    while (i < size) i *= 2;
    this->data.resize(i + 1);
  }
  void update(int index, int value) {
    index++;
    for (; index < (int)this->data.size(); index += index & (-index)) {
      this->data[index] += value;
    }
  }
  int query(int index) {
    int acc = 0;
    for (; index > 0; index -= index & (-index)) {
      acc += this->data[index];
    }
    return acc;
  }
  int query(int a, int b) { return query(b) - query(a); }
};
fenwick sums[4][10][10];
char base[128];
int main() {
  ios::sync_with_stdio(false);
  string dna;
  cin >> dna;
  base[(int)'A'] = 0;
  base[(int)'T'] = 1;
  base[(int)'G'] = 2;
  base[(int)'C'] = 3;
  for (int i = 0; i < 4; ++i) {
    for (int j = 1; j <= 10; ++j) {
      for (int k = 0; k < j; ++k) {
        sums[i][j - 1][k] = fenwick(dna.size() / j + 2);
      }
    }
  }
  for (int i = 0; i < (int)dna.size(); ++i) {
    for (int size = 1; size <= 10; ++size) {
      int chem = base[(int)dna[i]];
      int offset = i % size;
      int index = i / size;
      sums[chem][size - 1][offset].update(index, 1);
    }
  }
  int N;
  cin >> N;
  for (auto((i)) = (0); ((i)) != ((N)); ++((i))) {
    int t;
    cin >> t;
    if (t == 1) {
      int index;
      string character;
      cin >> index >> character;
      index--;
      for (int size = 1; size <= 10; ++size) {
        int oldchem = base[(int)dna[index]];
        int chem = base[(int)character[0]];
        int offset = index % size;
        int in = index / size;
        sums[oldchem][size - 1][offset].update(in, -1);
        sums[chem][size - 1][offset].update(in, 1);
      }
      dna[index] = character[0];
    } else {
      int l, r;
      string e;
      cin >> l >> r >> e;
      l--;
      int size = e.size();
      int acc = 0;
      for (auto((j)) = (0); ((j)) != ((size)); ++((j))) {
        int chem = base[(int)e[j]];
        int offset = (l + j) % size;
        int left = ceildiv(l - offset, size);
        int right = ceildiv(r - offset, size);
        if (left >= right) continue;
        int r = sums[chem][size - 1][offset].query(left, right);
        acc += r;
      }
      cout << acc << endl;
    }
  }
  return 0;
}
