#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main() {
int q,i;
char *a;
a=(char*) malloc(101);
scanf("%d%s",&q,a);
for(;q>0;q--){
int x;
scanf("%d",&x);
switch(x){
case 1:char m[101];scanf("%s",m);strcat(a,m);printf("%s",a);break;
case 2:char n[101];int c,d;scanf("%d%d",&c,&d);for(i=0;i<c;i++){a[i]=0;}a=a+c;
strncpy(n,a,d);strcpy(a,n);a[strlen(a)]='\0';printf("%s",a);break;
case 3:char l[101];int e,f;scanf("%d%s",&e,l);f=strlen(l);
for(i=f-1;i>=0;i--){a[e+i+f]=a[e+i];a[e+i]=l[i];
}a[strlen(a)]='\0';printf("%s",a);break;
case 4:char o[101];int g,h=0;int flag=-1;scanf("%s",o);if(strstr(a,o)!=NULL)printf("%d",strstr(a,o)-a);else printf("%d",flag);
break;
}
}return 0;
}
#include<stdlib.h>
#include<string.h>
int main() {
int q,i;
char *a;
a=(char*) malloc(101);
scanf("%d%s",&q,a);
for(;q>0;q--){
int x;
scanf("%d",&x);
switch(x){
case 1:char m[101];scanf("%s",m);strcat(a,m);printf("%s",a);break;
case 2:char n[101];int c,d;scanf("%d%d",&c,&d);for(i=0;i<c;i++){a[i]=0;}a=a+c;
strncpy(n,a,d);strcpy(a,n);a[strlen(a)]='\0';printf("%s",a);break;
case 3:char l[101];int e,f;scanf("%d%s",&e,l);f=strlen(l);
for(i=f-1;i>=0;i--){a[e+i+f]=a[e+i];a[e+i]=l[i];
}a[strlen(a)]='\0';printf("%s",a);break;
case 4:char o[101];int g,h=0;int flag=-1;scanf("%s",o);if(strstr(a,o)!=NULL)printf("%d",strstr(a,o)-a);else printf("%d",flag);
break;
}
}return 0;
}