#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct SegmentTree {
  using T = array<int, 21>;
  static T op(const T& a, const T& b) {
    T res;
    for (int i = 0; i <= 20; ++i) {
      res[i] = a[i] + b[i];
    }
    return res;
  }
  static T e() {
    T res;
    fill(begin(res), end(res), 0);
    return res;
  }
  using U = array<int, 21>;
  static void ap(const U& f, T& a) {
    T na;
    fill(begin(na), end(na), 0);
    for (int i = 0; i <= 20; ++i) {
      na[f[i]] += a[i];
    }
    a = na;
  }
  static void cp(const U& g, U& f) {
    T nf;
    for (int i = 0; i <= 20; ++i) {
      nf[i] = g[f[i]];
    }
    f = nf;
  }
  static U id() {
    U res;
    iota(begin(res), end(res), 0);
    return res;
  }

  const int n;
  V<T> t;
  V<U> u;
  SegmentTree(int n) : n(n), t(2 * n, e()), u(n, id()) {}
  T& operator[](int i) { return t[i + n]; }
  void build() { for (int i = n - 1; i; --i) t[i] = op(t[2 * i], t[2 * i + 1]); }
  void push() { for (int i = 1; i < n; ++i) push(i); }
  void apply(const U& f, int i) {
    ap(f, t[i]);
    if (i < n) cp(f, u[i]);
  }
  void push(int i) {
    if (u[i] == id()) return;
    apply(u[i], 2 * i);
    apply(u[i], 2 * i + 1);
    u[i] = id();
  }
  void push(int l, int r) {
    for (int hl = __lg(l + n), hr = __lg(r - 1 + n); hr > 0; --hl, --hr) {
      int al = l + n >> hl, ar = r - 1 + n >> hr;
      if (al < n) push(al);
      if (ar != al) push(ar);
    }
  }
  T acc(int l, int r) {
    push(l, r);
    T resl = e(), resr = e();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) resl = op(resl, t[l++]);
      if (r & 1) resr = op(t[--r], resr);
    }
    return op(resl, resr);
  }
  T get(int i) { return acc(i, i + 1); }
  void act(int l, int r, const U& f) {
    push(l, r);
    for (int i = l + n, j = r + n; i < j; i >>= 1, j >>= 1) {
      if (i & 1) apply(f, i++);
      if (j & 1) apply(f, --j);
    }
    l = l + n >> __builtin_ctz(l + n);
    while (l >>= 1) t[l] = op(t[2 * l], t[2 * l + 1]);
    r = r + n >> __builtin_ctz(r + n);
    while (r >>= 1) t[r] = op(t[2 * r], t[2 * r + 1]);
  }
  void set(int i, const T& a) {
    push(i, i + 1);
    t[i += n] = a;
    while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
  }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  string s; cin >> s;
  int m = s.size();
  int n, q; cin >> n >> q;
  SegmentTree st(n);
  for (int i = 0; i < n; ++i) {
    st[i] = st.e();
    st[i][0] = 1;
  }
  st.build();

  V<SegmentTree::U> g(26, st.id());
  for (char c = 'a'; c <= 'z'; ++c) {
    for (int i = 0; i <= m; ++i) {
      auto t = s.substr(0, i) + c;
      for (int j = min(i + 1, m); j >= 0; --j) {
        if (t.substr(i + 1 - j, j) == s.substr(0, j)) {
          g[c - 'a'][i] = j;
          break;
        }
      }
    }
  }

  while (q--) {
    int tp, l, r; cin >> tp >> l >> r, --l;
    if (tp == 1) {
      string t; cin >> t;
      auto f = SegmentTree::id();
      for (char c : t) {
        st.cp(g[c - 'a'], f);
      }
      st.act(l, r, f);
    } else {
      cout << st.acc(l, r)[m] << '\n';
    }
  }
}


Measured memory_bytes: 26820