#include <bits/stdc++.h>
using namespace std;
const int MAXE = 11;
const int MAXN = 1e5 + 1;
struct Node {
  Node* left;
  Node* right;
  int sum;
  Node() : left(NULL), right(NULL), sum(0){};
};
typedef Node* node;
int n;
int get_sum(node a, int L, int R, int LL = 0, int RR = n) {
  if (!a) return 0;
  if (L <= LL && RR <= R) {
    return a->sum;
  }
  if (RR <= L || R <= LL) {
    return 0;
  }
  int M = (LL + RR) / 2;
  return get_sum(a->left, L, R, LL, M) + get_sum(a->right, L, R, M, RR);
}
node upd_(node a, int x, int LL = 0, int RR = n) {
  if (LL > x || RR <= x) return a;
  if (!a) a = new Node();
  ++a->sum;
  if (RR - LL > 1) {
    int M = (LL + RR) / 2;
    a->left = upd_(a->left, x, LL, M);
    a->right = upd_(a->right, x, M, RR);
  }
  return a;
}
void del_(node a, int x, int LL = 0, int RR = n) {
  if (!a) return;
  if (LL > x || RR <= x) return;
  --a->sum;
  int M = (LL + RR) / 2;
  del_(a->left, x, LL, M);
  del_(a->right, x, M, RR);
}
node st[MAXE][MAXE][4];
int now[MAXN];
inline int ctoi(char a) {
  if (a == 'A') return 0;
  if (a == 'C') return 1;
  if (a == 'G') return 2;
  return 3;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string second;
  cin >> second;
  n = second.size();
  for (int i = 0; i < 4; ++i) {
    for (int j = 1; j <= 10; ++j) {
      for (int k = 0; k < j; ++k) {
        st[j][k][i] = NULL;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    now[i] = ctoi(second[i]);
  }
  for (int j = 1; j <= 10; ++j) {
    for (int i = 0; i < n; ++i) {
      st[j][i % j][now[i]] = upd_(st[j][i % j][now[i]], i);
    }
  }
  int m;
  int p;
  char c;
  cin >> m;
  int type;
  int l, r;
  string te;
  for (int i = 0; i < m; ++i) {
    cin >> type;
    if (type == 1) {
      cin >> p >> c;
      --p;
      int v = ctoi(c);
      for (int j = 1; j <= 10; ++j) {
        del_(st[j][p % j][now[p]], p);
        st[j][p % j][v] = upd_(st[j][p % j][v], p);
      }
      now[p] = v;
    } else {
      cin >> l >> r >> te;
      --l;
      int ans = 0;
      int ee = te.size();
      for (int i = 0; i < ee; ++i) {
        ans += get_sum(st[ee][(l + i) % ee][ctoi(te[i])], l, r);
      }
      cout << ans << '\n';
    }
  }
}
