#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
long long mod = 1e9 + 7;
double eps = 0.00000001;
double PI = acos(-1);
char str[maxn];
int sum[4][11][11][maxn], len;
map<char, int> mp;
int lowbit(int x) { return x & (-x); }
void add(int kind, int j, int k, int i, int x) {
  while (i <= maxn) {
    sum[kind][j][k][i] += x;
    i += lowbit(i);
  }
}
int getsum(int kind, int j, int k, int i) {
  int ans = 0;
  while (i > 0) {
    ans += sum[kind][j][k][i];
    i -= lowbit(i);
  }
  return ans;
}
int main() {
  scanf("%s", str + 1);
  memset(sum, 0, sizeof(sum));
  len = strlen(str + 1);
  mp['A'] = 0, mp['T'] = 1, mp['G'] = 2, mp['C'] = 3;
  for (int i = 1; i <= len; i++) {
    int kind = mp[str[i]];
    for (int j = 1; j <= 10; j++) {
      for (int k = 0; k <= j; k++) {
        if ((i - k) % j == 0) add(kind, j, k, i, 1);
      }
    }
  }
  int q, op;
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &op);
    if (op == 1) {
      int pos, kind;
      char st[2];
      scanf("%d%s", &pos, st);
      kind = mp[st[0]];
      for (int i = 1; i <= 10; i++) {
        for (int j = 0; j <= i; j++) {
          if ((pos - j) % i == 0) {
            add(kind, i, j, pos, 1);
            add(mp[str[pos]], i, j, pos, -1);
          }
        }
      }
      str[pos] = st[0];
    } else {
      int l, r, kind, len1, ans = 0;
      char st[25];
      scanf("%d%d%s", &l, &r, st);
      len1 = strlen(st);
      for (int i = 0; i < len1; i++) {
        int pp = (i + l) % len1;
        ans += getsum(mp[st[i]], len1, pp, r);
        ans -= getsum(mp[st[i]], len1, pp, l - 1);
      }
      printf("%d\n", ans);
    }
  }
}
