#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream &operator>>(istream &in, vector<T> &vec) {
  for (int i = 0; i < vec.size(); ++i) in >> vec[i];
  return in;
}
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); ++i) out << vec[i] << " ";
  return out;
}
void ans(int v = -1e9) {
  if (v == -1e9)
    cout << "Yes" << endl;
  else
    cout << v << endl;
  exit(0);
}
void err(bool check = 1) {
  if (check)
    cout << "No" << endl;
  else
    cout << -1 << endl;
  exit(0);
}
const int INF = 1e5 + 1;
unordered_map<char, int> book;
int x[4][11][11][INF];
string s;
void set1(int f[INF], int dx, int pos) {
  int size = s.size();
  for (int i = pos; i <= size; i |= i + 1) {
    f[i] += dx;
  }
}
int get(int f[INF], int i) {
  int res = 0;
  for (; i >= 1; i = (i & (i + 1)) - 1) res += f[i];
  return res;
}
int sum(int f[INF], int l, int r) { return get(f, r) - get(f, l - 1); }
void init(string &str) {
  int size = str.size();
  for (int i = 0; i < size; ++i) {
    for (int j = 1; j <= 10; ++j) {
      set1(x[book[str[i]]][j][i % j], 1, i + 1);
    }
  }
}
void swaper(char dest, int pos) {
  for (int i = 1; i <= 10; ++i) {
    set1(x[book[s[pos - 1]]][i][(pos - 1) % i], -1, pos);
    set1(x[book[dest]][i][(pos - 1) % i], 1, pos);
  }
  s[pos - 1] = dest;
}
int calc(int l, int r, string &str) {
  int j = min((int)(str.size()), (int)(r - l + 1));
  long long res = 0;
  long long dx = (l - 1) % j;
  for (int i = 0; i < j; ++i) {
    res += sum(x[book[str[i]]][j][(i + dx) % j], l, r);
  }
  return res;
}
void solve() {
  long long a, b;
  cin >> s;
  cin >> a;
  book['A'] = 0;
  book['T'] = 1;
  book['G'] = 2;
  book['C'] = 3;
  init(s);
  while (a--) {
    int l, r;
    cin >> l >> r;
    if (l == 1) {
      char c;
      cin >> c;
      swaper(c, r);
    } else {
      int m;
      string ss;
      cin >> m >> ss;
      cout << calc(r, m, ss) << endl;
    }
  }
}
int main(int argv, char *argc[]) {
  ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(12);
  solve();
  return 0;
}
