#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

template<typename Monoid,typename OperatorMonoid,typename F,typename G,typename H>
struct LazySegmentTree {
//	using F = function<Monoid(Monoid,Monoid)>;
//	using G = function<Monoid(Monoid,OperatorMonoid)>;
//	using H = function<OperatorMonoid(OperatorMonoid,OperatorMonoid)>;

	int sz,height;
	vec<Monoid> data;
	vec<OperatorMonoid> lazy;
	const F op;
	const G homo;
	const H comp;
  	const Monoid e;
	const OperatorMonoid Oe;

	LazySegmentTree(int n,const F op,const G homo,const H comp,
					const Monoid &e,const OperatorMonoid Oe)
		: op(op),homo(homo),comp(comp),e(e),Oe(Oe) {
		sz = 1;
		height = 0;
		while(sz<=n) sz <<= 1,height++;
		data.assign(2*sz,e);
		lazy.assign(2*sz,Oe);
	}

	void set(int k,const Monoid &x) {
		data[k+sz] = x;
	}

	void build() {
		for(int k=sz-1;k>0;k--) {
			data[k] = op(data[2*k], data[2*k+1]);
		}
	}

	inline void propagate(int k) {
		if(lazy[k]!=Oe) {
			lazy[2*k] = comp(lazy[2*k], lazy[k]);
			lazy[2*k+1] = comp(lazy[2*k+1], lazy[k]);
			data[k] = reflect(k);
			lazy[k] = Oe;
		}
	}

	inline Monoid reflect(int k) {
		return lazy[k] == Oe? data[k]:homo(data[k],lazy[k]);
	}

	inline void recalc(int k) {
		while(k>>=1) data[k] = op(reflect(2*k), reflect(2*k+1));
	}

	inline void thrust(int k) {
		for(int i=height;i>0;i--) propagate(k>>i);
	}

	void update(int a, int b, const OperatorMonoid &x) {
		thrust(a+=sz);
		thrust(b+=sz-1);
		for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
			if(l&1) lazy[l] = comp(lazy[l],x),++l;
			if(r&1) --r, lazy[r] = comp(lazy[r],x);
		}
		recalc(a);
		recalc(b);
	}

	Monoid query(int a, int b) {
		thrust(a+=sz);
		thrust(b+=sz-1);
		Monoid L = e, R = e;
		for(int l=a, r=b+1;l<r;l>>= 1,r>>=1) {
			if(l&1) L = op(L,reflect(l++));
			if(r&1) R = op(reflect(--r),R);
		}
		return op(L,R);
	}

	Monoid operator[](const int &k) {
		return query(k,k+1);
	}
};

using arr = array<int,21>;

vector<int> Z_algorithm(string S){
    int M = S.size();
    vector<int> A(M,0);
    A[0] = M;
    int i = 1,j = 0;
    while(i<M){
        while(i+j<M && S[j]==S[i+j]) j++;
        A[i] = j;
        if(j==0){
            i++;
            continue;
        }
        int k = 1;
        while(i+k<M && k+A[k]<j){
            A[i+k] = A[k];
            k++;
        }
        i += k; j -= k;
    }
    return A;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    int N,Q;
    cin >> S >> N >> Q;
	int n = S.size();
	auto op = [&](arr L,arr R){
		arr res{};
		for(int i=0;i<=n;i++) res[i] = L[i]+R[i];
		return res;
	};

	auto homo = [&](arr S,arr f){
		arr res{};
		for(int i=0;i<=n;i++) res[f[i]] += S[i];
		return res;
	};

	auto comp = [&](arr f,arr g){
		arr res{};
		for(int i=0;i<=n;i++) res[i] = g[f[i]];
		return res;
	};

	arr id{};
	for(int i=0;i<=20;i++) id[i] = i;
	LazySegmentTree<arr,arr,decltype(op),decltype(homo),decltype(comp)>
	seg(N,op,homo,comp,arr{},id);
	for(int i=0;i<N;i++){
		arr a{};
		a[0] = 1;
		seg.set(i,a);
	}
	seg.build();

	for(int i=0;i<Q;i++){
		int t;
		cin >> t;
		if(t==1){
			int l,r;
			string c;
			cin >> l >> r >> c;
			l--; r--;
			arr f{};
			int m = c.size();
			for(int i=0;i<=n;i++){
				string s = S.substr(0,i)+c;
				vec<int> res = Z_algorithm(S+s);
				for(int j=max(i+m,n);j<n+i+m;j++){
					if(j+res[j]==n+i+m) f[i] = max(f[i],min(res[j],n));
				}
			}
			seg.update(l,r+1,f);
		}else{
			int l,r;
			cin >> l >> r;
			l--; r--;
			cout << seg.query(l,r+1)[n] << "\n";
		}
	}
}


Measured memory_bytes: 45996