#include <iostream>
#include <string>
#include <vector>

using namespace std;

int len;

void ident(vector<int> &vec)
{
	for(int i = 0; i <= len; i++) vec[i] = i;
}
void ope(vector<int> &vec, vector<int> &op)
{
	vector<int> tmp = vec;
	//cout << "VEC "; for(int i = 0; i <= len; i++) cout << vec[i] << " "; cout << endl;
	//cout << "OP "; for(int i = 0; i <= len; i++) cout << op[i] << " "; cout << endl;
	for(int i = 0; i <= len; i++) vec[i] = 0;
	for(int i = 0; i <= len; i++) vec[op[i]] += tmp[i];
	//cout << "ANS "; for(int i = 0; i <= len; i++) cout << vec[i] << " "; cout << endl;
}
void mul(vector<int> &op, vector<int> &op2)
{
	vector<int> tmp = op;
	for(int i = 0; i <= len; i++) op[i] = op2[tmp[i]];
}
void merge(vector<int> &dest, vector<int> &src, vector<int> &src2)
{
	for(int i = 0; i <= len; i++) dest[i] = src[i] + src2[i];
}

struct SegTree{
	int size;
	vector<vector<int> > seg, delay;
	vector<int> flag;
	
	SegTree(){}
	SegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
		delay.resize(1<<(size+1));
		for(int i = 0; i < (1<<(size+1)); i++){
			seg[i].resize(len+1);
			delay[i].resize(len+1);
		}
		flag.resize(1<<(size+1));
	}
	
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++) ident(delay[i]);
	}
	
	void eval(int l, int r, int k)
	{
		if(flag[k]){
			ope(seg[k], delay[k]);
			if(l < r){
				mul(delay[k*2], delay[k]), flag[k*2] = true;
				mul(delay[k*2+1], delay[k]), flag[k*2+1] = true;
			}
			ident(delay[k]);
			flag[k] = false;
		}
	}
	
	void update(int i)
	{
		i += (1 << size);
		seg[i][0] = 1;
		while(i > 1){
			i /= 2;
			seg[i][0] = seg[i*2][0] + seg[i*2+1][0];
		}
	}
	
	void add(int a, int b, int k, int l, int r, vector<int> &val)
	{
		eval(l, r, k);
		
		if(b < l || r < a) return;
		if(a <= l && r <= b){
			mul(delay[k], val);
			flag[k] = true;
			eval(l, r, k);
			return;
		}
		add(a, b, k*2, l, (l+r)/2, val);
		add(a, b, k*2+1, (l+r)/2+1, r, val);
		merge(seg[k], seg[k*2], seg[k*2+1]);
	}
	void add(int a, int b, vector<int> &val){
		if(a > b) return;
		add(a, b, 1, 0, (1<<size)-1, val);
	}
 
	int query(int a, int b, int k, int l, int r)
	{
		eval(l, r, k);
		
		if(b < l || r < a) return 0;
		if(a <= l && r <= b) return seg[k][len];
		int lval = query(a, b, k*2, l, (l+r)/2);
		int rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return lval + rval;
	}
	int query(int a, int b)
	{
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

string s;
int n, Q;
int succ[25][26];
SegTree seg;

void get(vector<int> &vec, char c)
{
	for(int i = 0; i <= len; i++) vec[i] = succ[i][c-'a'];
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s;
	cin >> n >> Q;
	
	len = s.size();
	seg = SegTree(17);
	for(int i = 1; i <= n; i++) seg.update(i);
	
	for(int i = 0; i <= len; i++){
		for(int j = 0; j < 26; j++){
			string t = s.substr(0, i) + (char)(j+'a');
			int k = t.size();
			for(; k >= 0; k--){
				if(t == s.substr(0, k)) break;
				t = t.substr(1);
			}
			succ[i][j] = k;
		}
	}
	
	int t, l, r; string str;
	vector<int> vec(len+1), op(len+1);
	
	seg.init();
	
	for(int q = 0; q < Q; q++){
		cin >> t >> l >> r;
		if(t == 1){
			cin >> str;
			ident(vec);
			for(int i = 0; i < str.size(); i++){
				get(op, str[i]);
				mul(vec, op);
			}
			//for(int i = 0; i <= len; i++) cout << vec[i] << " "; cout << endl;
			seg.add(l, r, vec);
			/*for(int i = 1; i <= n; i++){
				cout << "["; for(int j = 0; j <= len; j++) cout << seg.seg[(1<<17)+i][j]; cout << "] ";
			}
			cout << endl;*/
		}
		else cout << seg.query(l, r) << "\n";
	}
	flush(cout);
	
	return 0;
}


Measured memory_bytes: 127700