#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int x, int y) {
  ++y;
  return (rng() % (y - x)) + x;
}
int n, m;
string A;
int ind(char ch) {
  if (ch == 'A') return 0;
  if (ch == 'T') return 1;
  if (ch == 'G') return 2;
  return 3;
}
struct node {
  int second, e, m;
  int v;
  node *l, *r;
  node(int _s, int _e) {
    second = _s, e = _e, m = (second + e) / 2;
    v = 0;
    if (second != e) {
    }
    l = NULL;
    r = NULL;
  }
  void update(int x, int nv) {
    if (second == e) {
      v += nv;
      return;
    }
    if (x > m) {
      create(r, m + 1, e);
      assert(r != NULL);
      r->update(x, nv);
    } else {
      create(l, second, m);
      assert(l != NULL);
      l->update(x, nv);
    }
    v = 0;
    v += get(l);
    v += get(r);
  }
  int rmq(int x, int y) {
    if (second == x && e == y) return v;
    if (x > m)
      return rcall(x, y);
    else if (y <= m)
      return lcall(x, y);
    else
      return lcall(x, m) + rcall(m + 1, y);
  }
  int rcall(int x, int y) {
    if (r == NULL) return 0;
    return r->rmq(x, y);
  }
  int lcall(int x, int y) {
    if (l == NULL) return 0;
    return l->rmq(x, y);
  }
  void create(node *&tmp, int x, int y) {
    if (tmp != NULL) return;
    tmp = new node(x, y);
    assert(tmp != NULL);
  }
  int get(node *l) {
    if (l == NULL) return 0;
    return l->v;
  }
} * seg[4][11][10];
void doo(int i, int op) {
  for (int j = 1; j < 11; j++) {
    { seg[ind(A[i])][j][i % j]->update(i, 1 * op); }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> A;
  n = A.length();
  cin >> m;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 11; j++)
      for (int k = 0; k < 10; k++) seg[i][j][k] = new node(0, n - 1);
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < 11; j++) {
      { seg[ind(A[i])][j][i % j]->update(i, 1); }
    }
  }
  for (int ii = 0; ii < m; ii++) {
    int op;
    cin >> op;
    if (op == 1) {
      int x, c;
      char ch;
      cin >> x >> ch;
      c = ind(ch);
      --x;
      doo(x, -1);
      A[x] = ch;
      doo(x, 1);
    } else {
      int l, r;
      string e;
      cin >> l >> r >> e;
      --l, --r;
      int ans = 0;
      for (int i = 0; i < e.length(); i++) {
        if (i + l > r) continue;
        ans +=
            seg[ind(e[i])][e.length()][((i + l) % (int)e.length())]->rmq(l, r);
      }
      cout << ans << "\n";
    }
  }
}
