#include <bits/stdc++.h>
using std::pair;
using std::vector;
using lint = long long int;
using pii = std::pair<int, int>;
using std::vector;
struct Fenwick {
 private:
  vector<long long> main, sub;
  int n;
  void update(int idx, int val, vector<long long>& tree) {
    while (idx <= n) {
      tree[idx] += val;
      idx += (idx & -idx);
    }
  }
  int query(int idx, vector<long long>& tree) {
    int ret = 0;
    while (idx) {
      ret += tree[idx];
      idx -= (idx & -idx);
    }
    return ret;
  }
  void update_main(int idx, int val) { update(idx, val, main); }
  void update_sub(int idx, int val) { update(idx, val, sub); }
  int query_main(int idx) { return query(idx, main); }
  int query_sub(int idx) { return query(idx, sub); }
  void startZero(int& left, int& right) {}

 public:
  Fenwick(int n) : n(n) {
    main.resize(n + 1, 0);
    sub.resize(n + 1, 0);
  }
  void rangeUpdate(int left, int right, int val) {
    startZero(left, right);
    right++;
    update_main(left, val);
    update_main(right, -val);
    update_sub(left, -val * (left - 1));
    update_sub(right, val * (right - 1));
  }
  int rangeQuery(int left, int right) {
    startZero(left, right);
    left--;
    int ret = 0;
    ret += query_main(right) * right + query_sub(right);
    ret -= query_main(left) * left + query_sub(left);
    return ret;
  }
};
char map[255];
char str[110000];
char tmp[15];
int main(void) {
  map['A'] = 0;
  map['C'] = 1;
  map['T'] = 2;
  map['G'] = 3;
  scanf("%s", str);
  int n = strlen(str);
  vector<Fenwick> tree[11][10];
  for (int p = 1; p <= 10; p++) {
    for (int b = 0; b < 10; b++) {
      for (int k = 0; k < 4; k++) {
        tree[p][b].push_back(Fenwick(n / p + 10));
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int p = 1; p <= 10; p++) {
      tree[p][i % p][map[str[i]]].rangeUpdate(i / p + 1, i / p + 1, 1);
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int a;
    scanf("%d", &a);
    if (a == 1) {
      int x;
      scanf("%d%s", &x, tmp);
      x--;
      for (int p = 1; p <= 10; p++) {
        tree[p][x % p][map[str[x]]].rangeUpdate(x / p + 1, x / p + 1, -1);
      }
      str[x] = tmp[0];
      for (int p = 1; p <= 10; p++) {
        tree[p][x % p][map[str[x]]].rangeUpdate(x / p + 1, x / p + 1, 1);
      }
    } else {
      int l, r;
      scanf("%d%d%s", &l, &r, tmp);
      l--;
      r--;
      int ans = 0;
      int m = strlen(tmp);
      for (int i = 0; i < m && l + i <= r; i++) {
        int right = (r / m) * m + (l + i) % m;
        if (right > r) {
          right = r / m;
        } else {
          right = r / m + 1;
        }
        ans += tree[m][(l + i) % m][map[tmp[i]]].rangeQuery((l + i) / m + 1,
                                                            right);
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
