#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int mapping[11][N], invMap[11][N], n;
string str;
struct node {
  int c[4] = {0, 0, 0, 0};
};
node tree[11][4 * N];
int c2i(int i) {
  if (str[i] == 'A') return 0;
  if (str[i] == 'C') return 1;
  if (str[i] == 'G') return 2;
  return 3;
}
void prepare() {
  for (int i = 1; i <= 10; i++) {
    int cnt = 0;
    for (int j = 0; j < i; j++) {
      for (int k = j; k < n; k += i) mapping[i][k] = cnt, invMap[i][cnt++] = k;
    }
  }
}
void buildTree(int pos, int l, int r, int dim) {
  if (l == r) {
    tree[dim][pos].c[c2i(invMap[dim][l])]++;
    return;
  }
  int mid = (l + r) / 2;
  buildTree(pos * 2, l, mid, dim);
  buildTree(pos * 2 + 1, mid + 1, r, dim);
  for (int i = 0; i < 4; i++)
    tree[dim][pos].c[i] = tree[dim][pos * 2].c[i] + tree[dim][pos * 2 + 1].c[i];
}
int get(int pos, int l, int r, int qLow, int qHigh, int dim, int id) {
  if (l > r || qLow > r || qHigh < l) return 0;
  if (l >= qLow && r <= qHigh) {
    return tree[dim][pos].c[id];
  }
  int mid = (l + r) / 2;
  return get(pos * 2, l, mid, qLow, qHigh, dim, id) +
         get(pos * 2 + 1, mid + 1, r, qLow, qHigh, dim, id);
}
void update(int pos, int l, int r, int x, int dim, int oldId, int newId) {
  if (l > r || x > r || x < l) return;
  if (l == r) {
    tree[dim][pos].c[oldId]--;
    tree[dim][pos].c[newId]++;
    return;
  }
  int mid = (l + r) / 2;
  update(pos * 2, l, mid, x, dim, oldId, newId);
  update(pos * 2 + 1, mid + 1, r, x, dim, oldId, newId);
  for (int i = 0; i < 4; i++)
    tree[dim][pos].c[i] = tree[dim][pos * 2].c[i] + tree[dim][pos * 2 + 1].c[i];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> str;
  n = str.length();
  str += 'a';
  prepare();
  for (int i = 1; i <= 10; i++) buildTree(1, 0, n - 1, i);
  int q, t, x, y;
  string temp;
  cin >> q;
  while (q--) {
    cin >> t;
    if (t == 1) {
      char c;
      cin >> x >> c;
      x--;
      str[n] = c;
      for (int i = 1; i <= 10; i++)
        update(1, 0, n - 1, mapping[i][x], i, c2i(x), c2i(n));
      str[x] = c;
    } else {
      cin >> x >> y >> temp;
      long long ans = 0;
      x--, y--;
      int len = temp.length();
      for (int i = 0; i < len; i++) {
        int currX = x + i;
        int currY = (y - currX) / len;
        currY = currX + currY * len;
        if (currX > y) break;
        str[n] = temp[i];
        if (currX <= currY && currX >= x && currY <= y)
          ans += get(1, 0, n - 1, mapping[len][currX], mapping[len][currY], len,
                     c2i(n));
      }
      cout << ans << endl;
    }
  }
  return 0;
}
