#include <bits/stdc++.h>
using namespace std;
const int size1 = 1e5;
const int INF = 1e9;
string s;
struct vertex {
  int a = 0;
  int t = 0;
  int g = 0;
  int c = 0;
};
vector<vector<int> > num(size1);
vector<vector<vector<vertex> > > tree(11);
vector<vector<vector<char> > > v(11);
void build_tree(int pok, int pok1, int tl, int tr, int pos) {
  if (tl == tr) {
    char c = v[pok][pok1][tl];
    if (c == 'A') {
      tree[pok][pok1][pos].a = 1;
    }
    if (c == 'T') {
      tree[pok][pok1][pos].t = 1;
    }
    if (c == 'G') {
      tree[pok][pok1][pos].g = 1;
    }
    if (c == 'C') {
      tree[pok][pok1][pos].c = 1;
    }
  } else {
    int tm = (tl + tr) / 2;
    build_tree(pok, pok1, tl, tm, pos * 2);
    build_tree(pok, pok1, tm + 1, tr, pos * 2 + 1);
    tree[pok][pok1][pos].a =
        tree[pok][pok1][pos * 2].a + tree[pok][pok1][pos * 2 + 1].a;
    tree[pok][pok1][pos].t =
        tree[pok][pok1][pos * 2].t + tree[pok][pok1][pos * 2 + 1].t;
    tree[pok][pok1][pos].g =
        tree[pok][pok1][pos * 2].g + tree[pok][pok1][pos * 2 + 1].g;
    tree[pok][pok1][pos].c =
        tree[pok][pok1][pos * 2].c + tree[pok][pok1][pos * 2 + 1].c;
  }
}
void update1(int num1, char c, char c1, int pok, int pok1, int tl, int tr,
             int pos) {
  if (tl == tr) {
    if (c == 'A') {
      tree[pok][pok1][pos].a--;
    }
    if (c == 'T') {
      tree[pok][pok1][pos].t--;
    }
    if (c == 'G') {
      tree[pok][pok1][pos].g--;
    }
    if (c == 'C') {
      tree[pok][pok1][pos].c--;
    }
    if (c1 == 'A') {
      tree[pok][pok1][pos].a++;
    }
    if (c1 == 'T') {
      tree[pok][pok1][pos].t++;
    }
    if (c1 == 'G') {
      tree[pok][pok1][pos].g++;
    }
    if (c1 == 'C') {
      tree[pok][pok1][pos].c++;
    }
  } else {
    int tm = (tl + tr) / 2;
    if (tl <= num1 && num1 <= tm) {
      update1(num1, c, c1, pok, pok1, tl, tm, pos * 2);
    } else {
      update1(num1, c, c1, pok, pok1, tm + 1, tr, pos * 2 + 1);
    }
    tree[pok][pok1][pos].a =
        tree[pok][pok1][pos * 2].a + tree[pok][pok1][pos * 2 + 1].a;
    tree[pok][pok1][pos].t =
        tree[pok][pok1][pos * 2].t + tree[pok][pok1][pos * 2 + 1].t;
    tree[pok][pok1][pos].g =
        tree[pok][pok1][pos * 2].g + tree[pok][pok1][pos * 2 + 1].g;
    tree[pok][pok1][pos].c =
        tree[pok][pok1][pos * 2].c + tree[pok][pok1][pos * 2 + 1].c;
  }
}
int sum(char c, int pok, int pok1, int l, int r, int tl, int tr, int pos) {
  if (l <= tl && tr <= r) {
    if (c == 'A') {
      return tree[pok][pok1][pos].a;
    }
    if (c == 'T') {
      return tree[pok][pok1][pos].t;
    }
    if (c == 'G') {
      return tree[pok][pok1][pos].g;
    }
    if (c == 'C') {
      return tree[pok][pok1][pos].c;
    }
  } else {
    int res = 0;
    int tm = (tl + tr) / 2;
    if (max(l, tl) <= min(r, tm)) {
      res += sum(c, pok, pok1, l, r, tl, tm, pos * 2);
    }
    if (max(l, tm + 1) <= min(r, tr)) {
      res += sum(c, pok, pok1, l, r, tm + 1, tr, pos * 2 + 1);
    }
    return res;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int i, j, k;
  cin >> s;
  int n = s.size();
  s = ' ' + s;
  for (i = 1; i <= 10; i++) {
    tree[i].resize(i);
    for (j = 0; j < i; j++) {
      tree[i][j].resize(4 * (n / i + 1));
    }
  }
  for (i = 1; i <= n; i++) {
    num[i].resize(11);
  }
  for (i = 1; i <= 10; i++) {
    v[i].resize(11);
  }
  for (i = 1; i <= 10; i++) {
    for (j = 0; j < i; j++) {
      v[i][j].push_back(0);
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= 10; j++) {
      if (i > j) {
        num[i][j] = num[i - j][j] + 1;
      } else {
        num[i][j] = 1;
      }
      v[j][i % j].push_back(s[i]);
    }
  }
  for (i = 1; i <= 10; i++) {
    for (j = 0; j < i; j++) {
      if (v[i][j].size() > 1) {
        build_tree(i, j, 1, v[i][j].size() - 1, 1);
      }
    }
  }
  int q;
  cin >> q;
  for (i = 1; i <= q; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      int pos;
      char c;
      cin >> pos >> c;
      for (j = 1; j <= 10; j++) {
        update1(num[pos][j], s[pos], c, j, pos % j, 1, v[j][pos % j].size() - 1,
                1);
      }
      s[pos] = c;
    } else {
      int l, r;
      string s1;
      cin >> l >> r >> s1;
      int ans = 0;
      int m = s1.size();
      for (j = 0; j < min(int(s1.size()), r - l + 1); j++) {
        int sum1 = sum(s1[j], m, (l + j) % m, num[l + j][m],
                       num[r - ((r - l - j) % m + m) % m][m], 1,
                       v[m][(l + j) % m].size() - 1, 1);
        ans += sum1;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
