#include <bits/stdc++.h>
using namespace std;
struct node {
  int cnt[4];
  node *lt, *rt;
  node() {
    memset(cnt, 0, sizeof(cnt));
    lt = rt = NULL;
  }
  void update(int l, int r, int tar, int ch, int delta) {
    cnt[ch] += delta;
    if (l == r) return;
    int mid = (l + r) / 2;
    if (tar <= mid)
      lt->update(l, mid, tar, ch, delta);
    else
      rt->update(mid + 1, r, tar, ch, delta);
  }
  int query(int l, int r, int tl, int tr, int ch) {
    if (tl <= l && r <= tr) return cnt[ch];
    int mid = (l + r) / 2;
    int ret = 0;
    if (tl <= mid) ret += lt->query(l, mid, tl, tr, ch);
    if (tr > mid) ret += rt->query(mid + 1, r, tl, tr, ch);
    return ret;
  }
  void build(int l, int r) {
    if (l == r) return;
    int mid = (l + r) / 2;
    lt = new node();
    rt = new node();
    lt->build(l, mid);
    rt->build(mid + 1, r);
  }
} root[11][10];
int trans[200];
int n, q, first, second, z, a[100555];
char s[100555], e[20], c;
int main() {
  trans['A'] = 0;
  trans['C'] = 1;
  trans['G'] = 2;
  trans['T'] = 3;
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < n; i++) a[i] = trans[s[i]];
  for (int i = 1; i <= 10; i++)
    for (int j = 0; j < i; j++) root[i][j].build(0, n / i + 1);
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= 10; j++)
      root[j][i % j].update(0, n / j + 1, i / j, a[i], +1);
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &first, &second);
    second--;
    if (first == 1) {
      scanf(" %c", &c);
      int ch = trans[c];
      for (int j = 1; j <= 10; j++) {
        root[j][second % j].update(0, n / j + 1, second / j, a[second], -1);
        root[j][second % j].update(0, n / j + 1, second / j, ch, +1);
      }
      a[second] = ch;
    }
    if (first == 2) {
      scanf("%d%s", &z, e);
      z--;
      int len = strlen(e);
      int ans = 0;
      for (int j = 0; j < len; j++) {
        int L = second / len;
        int R = z / len;
        if (j < second % len) L++;
        if (j > z % len) R--;
        if (L <= R)
          ans += root[len][j].query(0, n / len + 1, L, R,
                                    trans[e[((j - second) % len + len) % len]]);
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
