#include <bits/stdc++.h>
using namespace std;
int a[11][11][100005][4];
string s;
int code(char x) {
  if (x == 'A')
    return 0;
  else if (x == 'T')
    return 1;
  else if (x == 'G')
    return 2;
  else
    return 3;
}
void update(int vlen, int del, int i, int m, int val) {
  for (; i <= 100000; i = i | (i + 1)) {
    a[vlen][del][i][m] += val;
  }
}
string norm(string& v, int l) {
  l %= v.length();
  string ans;
  int cnt = 0;
  for (int i = v.length() - l; cnt < v.length(); i++, cnt++) {
    if (i >= v.length()) i -= v.length();
    ans += v[i];
  }
  return ans;
}
int sum(int vlen, int del, int i, int m) {
  int ans = 0;
  for (; i >= 0; i = (i & (i + 1)) - 1) {
    ans += a[vlen][del][i][m];
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> s;
  for (int i = 1; i <= 10; i++) {
    for (int j = 0; j < i; j++) {
      for (int k = 0; k <= 100000; k++) {
        for (int m = 0; m < 4; m++) {
          a[i][j][k][m] = 0;
        }
      }
    }
  }
  for (int i = 1; i <= 10; i++) {
    for (int j = 0; j < i; j++) {
      for (int k = 0; k < s.length(); k++) {
        for (int m = 0; m < 4; m++) {
          int ind = k * i + j;
          if (ind >= s.length()) continue;
          if (code(s[ind]) == m) update(i, j, k, m, 1);
        }
      }
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int com;
    cin >> com;
    if (com == 1) {
      int pos;
      cin >> pos;
      pos--;
      char x;
      cin >> x;
      int c = code(x);
      int oldC = code(s[pos]);
      for (int vlen = 1; vlen <= 10; vlen++) {
        for (int delta = 0; delta < vlen; delta++) {
          if ((pos - delta) % vlen != 0) continue;
          int i = (pos - delta) / vlen;
          update(vlen, delta, i, c, 1);
          update(vlen, delta, i, oldC, -1);
        }
      }
      s[pos] = x;
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      string v;
      cin >> v;
      v = norm(v, l);
      int ans = 0;
      for (int j = 0; j < v.length(); j++) {
        int c = code(v[j]);
        if (r - j >= 0) ans += sum(v.length(), j, (r - j) / v.length(), c);
        if (l - 1 - j >= 0)
          ans -= sum(v.length(), j, (l - 1 - j) / v.length(), c);
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
