#include <bits/stdc++.h>
using namespace std;
int t[11][11][4][100001];
int q, N = 1e5, n;
string s;
inline int f(char ch) {
  if (ch == 'A') return 0;
  if (ch == 'T') return 1;
  if (ch == 'G') return 2;
  if (ch == 'C') return 3;
}
int sum(int a, int b, int c, int r) {
  int result = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) result += t[a][b][c][r];
  return result;
}
void inc(int a, int b, int c, int i, int delta) {
  for (; i < n; i = (i | (i + 1))) t[a][b][c][i] += delta;
}
int sum(int a, int b, int c, int l, int r) {
  return sum(a, b, c, r) - sum(a, b, c, l - 1);
}
int main() {
  cin >> s;
  s = '!' + s;
  n = s.length();
  for (int i = 1; i <= s.length(); i++) {
    for (int j = 1; j <= 10; j++) {
      int y = i % j;
      inc(j, y, f(s[i]), i, 1);
    }
  }
  cin >> q;
  string h;
  while (q--) {
    int x, l, r;
    scanf("%d", &x);
    if (x == 1) {
      scanf("%d", &x);
      cin >> h;
      for (int j = 1; j <= 10; j++) {
        int y = x % j;
        inc(j, y, f(s[x]), x, -1);
      }
      s[x] = h[0];
      for (int j = 1; j <= 10; j++) {
        int y = x % j;
        inc(j, y, f(s[x]), x, 1);
      }
    } else {
      scanf("%d%d", &l, &r);
      cin >> h;
      int y = 0;
      for (int i = 0; i < h.size(); i++) {
        y += sum(h.size(), (l + i) % h.size(), f(h[i]), l, r);
      }
      cout << y << endl;
    }
  }
  return 0;
}
