//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

namespace n91 {

  using i8 = std::int_fast8_t;
  using i32 = std::int_fast32_t;
  using i64 = std::int_fast64_t;
  using u8 = std::uint_fast8_t;
  using u32 = std::uint_fast32_t;
  using u64 = std::uint_fast64_t;
  using isize = std::ptrdiff_t;
  using usize = std::size_t;

  constexpr usize operator"" _z(unsigned long long x) noexcept {
    return static_cast<usize>(x);
  }

  template <class T> class integral_iterator {
  public:
    using difference_type = T;
    using value_type = T;
    using pointer = const value_type*;
    using reference = value_type;
    using iterator_category = std::random_access_iterator_tag;

  private:
    using self_type = integral_iterator<value_type>;
    value_type i;

  public:
    constexpr integral_iterator() noexcept : i() {}
    explicit constexpr integral_iterator(const value_type i) noexcept : i(i) {}
    constexpr self_type operator++(int) noexcept { return self_type(i++); }
    constexpr self_type operator--(int) noexcept { return self_type(i--); }
    constexpr self_type operator[](const difference_type rhs) const noexcept {
      return self_type(i + rhs);
    }
    constexpr self_type& operator++() noexcept {
      ++i;
      return *this;
    }
    constexpr self_type& operator--() noexcept {
      --i;
      return *this;
    }
    constexpr reference operator*() const noexcept { return i; }
    constexpr self_type operator+(const difference_type rhs) const noexcept {
      return self_type(i + rhs);
    }
    constexpr self_type operator-(const difference_type rhs) const noexcept {
      return self_type(i - rhs);
    }
    constexpr difference_type operator-(const self_type rhs) const noexcept {
      return i - rhs.i;
    }
    constexpr bool operator<(const self_type rhs) const noexcept {
      return i < rhs.i;
    }
    constexpr bool operator<=(const self_type rhs) const noexcept {
      return i <= rhs.i;
    }
    constexpr bool operator>(const self_type rhs) const noexcept {
      return i > rhs.i;
    }
    constexpr bool operator>=(const self_type rhs) const noexcept {
      return i >= rhs.i;
    }
    constexpr bool operator==(const self_type rhs) const noexcept {
      return i == rhs.i;
    }
    constexpr bool operator!=(const self_type rhs) const noexcept {
      return i != rhs.i;
    }
    constexpr self_type& operator+=(const difference_type rhs) noexcept {
      i += rhs;
      return *this;
    }
    constexpr self_type& operator-=(const difference_type rhs) noexcept {
      i -= rhs;
      return *this;
    }
  };
  template <class T>
  constexpr integral_iterator<T> make_int_itr(const T i) noexcept {
    return integral_iterator<T>(i);
  }
  class rep {
    const usize f, l;

  public:
    constexpr rep(const usize f, const usize l) noexcept : f(f), l(l) {}
    constexpr auto begin() const noexcept { return make_int_itr(f); }
    constexpr auto end() const noexcept { return make_int_itr(l); }
  };
  class revrep {
    const usize f, l;

  public:
    revrep(const usize f, const usize l) noexcept : f(l), l(f) {}
    auto begin() const noexcept {
      return std::make_reverse_iterator(make_int_itr(f));
    }
    auto end() const noexcept {
      return std::make_reverse_iterator(make_int_itr(l));
    }
  };
  template <class T> auto md_vec(const usize n, const T& value) {
    return std::vector<T>(n, value);
  }
  template <class... Args> auto md_vec(const usize n, Args... args) {
    return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
  }
  template <class T> constexpr T difference(const T& a, const T& b) {
    return a < b ? b - a : a - b;
  }
  template <class T> T scan() {
    T ret;
    std::cin >> ret;
    return ret;
  }

} // namespace n91

#include <cassert>
#include <iterator>
#include <stdexcept>
#include <utility>

template <class value_type, class operator_type, class F, class G, class H,
  class F2, class H2>
  class lazy_segment_tree {
  public:
    using container_type = std::vector<::std::pair<value_type, operator_type>>;
    using size_type = typename container_type::size_type;

  private:
    value_type vi;
    operator_type oi;
    F f;
    G g;
    H h;
    F2 f2;
    H2 h2;

    size_type size_, height;
    container_type tree;
    static size_type getheight(const size_type size) noexcept {
      size_type ret = 0;
      while (static_cast<size_type>(1) << ret < size)
        ++ret;
      return ret;
    }
    value_type reflect(typename container_type::const_reference element) {
      return h(element.first, element.second);
    }
    void recalc(const size_type index) {
      f2(tree[index].first, reflect(tree[index << 1]),
        reflect(tree[index << 1 | 1]));
    }
    void assign(operator_type& element, const operator_type& data) {
      g(element, data);
    }
    void push(const size_type index) {
      assign(tree[index << 1].second, tree[index].second);
      assign(tree[index << 1 | 1].second, tree[index].second);
      tree[index].second = oi;
    }
    void propagate(const size_type index) {
      for (size_type i = height; i; --i)
        push(index >> i);
    }
    void thrust(const size_type index) {
      h2(tree[index].first, tree[index].second);
      push(index);
    }
    void evaluate(const size_type index) {
      for (size_type i = height; i; --i)
        thrust(index >> i);
    }
    void build(size_type index) {
      while (index >>= 1)
        recalc(index);
    }
    size_type base_size() const { return static_cast<size_type>(1) << height; }

  public:
    lazy_segment_tree() : size_(0), height(0), tree() {}
    explicit lazy_segment_tree(const size_type size, value_type def,
      value_type vi, operator_type oi, F f, G g, H h,
      F2 f2, H2 h2)
      : vi(vi), oi(oi), f(f), g(g), h(h), f2(f2), h2(h2), size_(size),
      height(getheight(size_)),
      tree(static_cast<size_type>(1) << (height + 1), { def, oi }) {
      for (size_type i = tree.size() / 2 - 1; i; --i)
        recalc(i);
    }

    bool empty() const { return !size_; }
    size_type size() const { return size_; }
    value_type fold(size_type first, size_type last) {
      assert(first <= last);
      assert(first <= size());
      assert(last <= size());
      first += base_size();
      last += base_size();
      evaluate(first);
      evaluate(last - 1);
      value_type ret_l = vi, ret_r = vi;
      for (; first < last; first >>= 1, last >>= 1) {
        if (first & 1)
          f2(ret_l, ret_l, reflect(tree[first++]));
        if (last & 1)
          f2(ret_r, reflect(tree[last - 1]), ret_r);
      }
      return f(ret_l, ret_r);
    }
    void update(size_type first, size_type last, const operator_type& data) {
      assert(first <= last);
      assert(first <= size());
      assert(last <= size());
      first += base_size();
      last += base_size();
      propagate(first);
      propagate(last - 1);
      for (size_type left = first, right = last; left < right;
        left >>= 1, right >>= 1) {
        if (left & 1)
          assign(tree[left++].second, data);
        if (right & 1)
          assign(tree[right - 1].second, data);
      }
      build(first);
      build(last - 1);
    }
};

#include <algorithm>
#include <array>
#include <iostream>
#include <string>
#include <utility>

namespace n91 {

  void main_() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    const std::string s = scan<std::string>();
    const usize stsize = s.size() + 1_z;
    auto tr = md_vec(s.size() + 1_z, 26_z, usize());
    for (const auto i : rep(0_z, s.size() + 1_z)) {
      const std::string x = s.substr(0_z, i);
      for (const auto k : rep(0_z, 26_z)) {
        std::string t(x);
        t.push_back('a' + k);
        while (t != s.substr(0_z, t.size())) {
          t.erase(t.begin());
        }
        tr[i][k] = t.size();
      }
    }
    const usize n = scan<usize>();
    const usize q = scan<usize>();
    using value_t = std::vector<usize>;
    using operator_t = std::vector<usize>;
    const auto f = [&](const value_t& l, const value_t& r) {
      value_t ret(stsize);
      for (const auto i : rep(0_z, stsize)) {
        ret[i] = l[i] + r[i];
      }
      return std::move(ret);
    };
    const auto f2 = [&](value_t& dst, const value_t& l, const value_t& r) {
      for (const auto i : rep(0_z, stsize)) {
        dst[i] = l[i] + r[i];
      }
    };
    const auto g = [&](operator_t& l, const operator_t& r) {
      l.insert(l.end(), r.cbegin(), r.cend());
      if (l.size() > s.size()) {
        l.erase(l.begin(), l.end() - s.size());
      }
    };
    value_t storage(stsize);
    const auto h = [&](const value_t& l, const operator_t& r) {
      value_t ret(stsize);
      for (const auto i : rep(0_z, stsize)) {
        usize k = i;
        for (const auto e : r) {
          k = tr[k][e];
        }
        ret[k] += l[i];
      }
      return std::move(ret);
    };
    const auto h2 = [&](value_t& l, const operator_t& r) {
      l = h(l, r);
    };
    value_t def(stsize, 0_z);
    def[0] = 1;
    lazy_segment_tree<value_t, operator_t, decltype(f), decltype(g), decltype(h),
      decltype(f2), decltype(h2)>
      lsg(n, def, value_t(stsize, 0_z), operator_t(), f, g, h, f2, h2);

    for (const auto i : rep(0_z, q)) {
      const u32 typ = scan<u32>();
      if (typ == 1) {
        const usize l = scan<usize>() - 1_z;
        const usize r = scan<usize>();
        const std::string c = scan<std::string>();
        operator_t op(c.size());
        for (const auto i : rep(0_z, c.size())) {
          op[i] = c[i] - 'a';
        }
        lsg.update(l, r, op);
      }
      else {
        const usize l = scan<usize>() - 1_z;
        const usize r = scan<usize>();
        std::cout << lsg.fold(l, r)[s.size()] << std::endl;
      }
    }
    return;
  }

} // namespace n91

int main() {
  n91::main_();
  return 0;
}




Measured memory_bytes: 115084