#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 500005

int N = 1;
int LEN;
int num[SIZE][25],table[SIZE][25];
int shift[25],num_work[25];
int next_loc[25][26];
bool have_info[SIZE];
char S[25],work[25];


void init(int first_N){
	while(N < first_N)N *= 2;
}

void update_first(int loc){

	loc += N-1;

	num[loc][0] = 1;

	if(N == 1)return;

	int parent = (loc-1)/2;

	while(true){
		num[parent][0] = num[2*parent+1][0]+num[2*parent+2][0];

		if(parent == 0)break;
		else{
			parent = (parent-1)/2;
		}
	}
}

void calc(int node_id){

	for(int i = 0; i <= LEN; i++){

		num_work[i] = 0;
	}
	for(int i = 0; i <= LEN; i++){

		num_work[table[node_id][i]] += num[node_id][i];
	}
	for(int i = 0; i <= LEN; i++){

		num[node_id][i] = num_work[i];
	}
}

void update(int search_left,int search_right,int node_id,int node_left,int node_right){

	int left_child = 2*node_id+1;
	int right_child = 2*node_id+2;

	if(have_info[node_id]){

		calc(node_id);

		if(node_left < node_right){

			for(int i = 0; i <= LEN; i++){

				table[left_child][i] = table[node_id][table[left_child][i]];
				table[right_child][i] = table[node_id][table[right_child][i]];
			}
			have_info[left_child] = true;
			have_info[right_child] = true;
		}
		for(int i = 0; i <= LEN; i++){
			table[node_id][i] = i;
		}
		have_info[node_id] = false;
	}

	if(search_right < node_left || search_left > node_right)return;

	if(search_left <= node_left && search_right >= node_right){

		for(int i = 0; i <= LEN; i++){

			table[node_id][i] = shift[table[node_id][i]];
		}

		calc(node_id);

		if(node_left < node_right){

			for(int i = 0; i <= LEN; i++){

				table[left_child][i] = table[node_id][table[left_child][i]];
				table[right_child][i] = table[node_id][table[right_child][i]];
			}
			have_info[left_child] = true;
			have_info[right_child] = true;
		}

		for(int i = 0; i <= LEN; i++){
			table[node_id][i] = i;
		}
		return;
	}
	update(search_left,search_right,left_child,node_left,(node_left+node_right)/2);
	update(search_left,search_right,right_child,(node_left+node_right)/2+1,node_right);

	for(int i = 0; i <= LEN; i++){

		num[node_id][i] = num[left_child][i]+num[right_child][i];
	}
}

int query(int search_left,int search_right,int node_id,int node_left,int node_right){

	int left_child = 2*node_id+1;
	int right_child = 2*node_id+2;

	if(have_info[node_id]){

		calc(node_id);

		if(node_left < node_right){

			for(int i = 0; i <= LEN; i++){

				table[left_child][i] = table[node_id][table[left_child][i]];
				table[right_child][i] = table[node_id][table[right_child][i]];
			}
			have_info[left_child] = true;
			have_info[right_child] = true;
		}
		for(int i = 0; i <= LEN; i++){
			table[node_id][i] = i;
		}
		have_info[node_id] = false;
	}

	if(search_right < node_left || search_left > node_right){
		return 0;
	}

	if(search_left <= node_left && search_right >= node_right){

		return num[node_id][LEN];
	}

	int left = query(search_left,search_right,left_child,node_left,(node_left+node_right)/2);
	int right =  query(search_left,search_right,right_child,(node_left+node_right)/2+1,node_right);

	return left+right;
}

int main(){

	scanf("%s",S);

	for(LEN = 0; S[LEN] != '\0'; LEN++);

	int index,head,max_match_len;

	for(int len = 0; len <= LEN; len++){
		for(index = 0; index < len; index++){

			work[index] = S[index];
		}
		for(int ch = 0; ch < 26; ch++){

			work[index] = 'a'+ch;

			if(len == LEN){

				head = 1;
			}else{

				head = 0;
			}

			max_match_len = 0;

			for(int i = head; i <= index; i++){

				bool FLG = true;
				for(int k = i; k <= index; k++){
					if(work[k] != S[k-i]){

						FLG = false;
						break;
					}
				}
				if(FLG){
					max_match_len = index-i+1;
					break;
				}
			}
			next_loc[len][ch] = max_match_len;
		}
	}

	int first_N,num_query;
	scanf("%d %d",&first_N,&num_query);

	init(first_N);

	for(int i = 0; i <= 2*N-2; i++){
		have_info[i] = false;
		for(int k = 0; k <= LEN; k++){
			num[i][k] = 0;
			table[i][k] = k;
		}
	}

	for(int i = 0; i < first_N; i++){

		update_first(i);
	}

	int command,left,right;

	for(int i = 0; i < num_query; i++){
		scanf("%d",&command);

		if(command == 2){

			scanf("%d %d",&left,&right);
			left--;
			right--;

			printf("%d\n",query(left,right,0,0,N-1));

		}else{
			scanf("%d %d %s",&left,&right,work);
			left--;
			right--;

			for(int k = 0; k <= LEN; k++){

				shift[k] = k;
			}
			for(int a = 0; work[a] != '\0'; a++){
				for(int k = 0; k <= LEN; k++){

					shift[k] = next_loc[shift[k]][work[a]-'a'];
				}
			}

			update(left,right,0,0,N-1);
		}
	}
	return 0;
}



Measured memory_bytes: 54696