#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
struct seg {
  vector<int> t;
  int n;
  seg(int n = 0) : t(2 * n), n(n) {}
  int query(int l, int r) {
    int ans = 0;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) ans += t[l++];
      if (r & 1) ans += t[--r];
    }
    return ans;
  }
  void update(int p, int v) {
    for (t[p += n] += v; p > 1; p >>= 1) {
      t[p >> 1] = t[p] + t[p ^ 1];
    }
  }
};
seg s[4][11][10];
void modify(int p, int c, int m) {
  for (int i = 1; i <= 10; i++) {
    s[c][i][p % i].update(p, m);
  }
}
void convert(string& s) {
  for (char& c : s) {
    switch (c) {
      case 'A':
        c = 0;
        break;
      case 'T':
        c = 1;
        break;
      case 'C':
        c = 2;
        break;
      case 'G':
        c = 3;
        break;
    }
  }
}
int main() {
  string k;
  cin >> k;
  convert(k);
  for (int i = 0; i < 4; i++) {
    for (int j = 1; j <= 10; j++) {
      for (int l = 0; l < j; l++) {
        s[i][j][l] = seg(k.size());
      }
    }
  }
  for (int i = 0; i < k.size(); i++) {
    modify(i, k[i], 1);
  }
  int q;
  cin >> q;
  while (q--) {
    int op;
    cin >> op;
    if (op == 1) {
      int x;
      string c;
      cin >> x >> c;
      convert(c);
      x--;
      modify(x, k[x], -1);
      k[x] = c[0];
      modify(x, k[x], 1);
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      string e;
      cin >> e;
      convert(e);
      int a = 0;
      for (int i = l; i < l + e.size(); i++) {
        a += s[e[i - l]][e.size()][i % e.size()].query(l, r);
      }
      cout << a << "\n";
    }
  }
  return 0;
}
