#include <bits/stdc++.h>
using namespace std;
#define ll int
#define mo 1000000007
map<ll,ll>trie[26][26];
ll sz=0;
char p[500005],c[500005];
void ins(string s,ll root)
{
ll st=0;
for(ll i=0;i<s.size();i++)
{
ll cur=s[i]-65;
if(trie[root][cur][st]==0)
trie[root][cur][st]=++sz;
st=trie[root][cur][st];
}
}
ll ch(string s,ll root)
{
ll st=0;
for(ll i=0;i<s.size();i++)
{
ll cur=s[i]-65;
if(trie[root][cur][st]==0)
return 0;
st=trie[root][cur][st];
}
return 1;
}
int main()
{
ll i,j,k,n,m,t;
scanf("%d %d",&n,&t);
scanf("%s",p);
map<char,char>vk;
for(i=0;i<n;i++)
{
char now=(char)(i+65);
vk[now]=p[i];
}
ll f=0;
while(t--)
{
ll tp;
scanf("%d",&tp);
if(tp==1)
{
scanf("%s",c);
ins(c,0);
string pre=c;
for(i=1;i<n;i++)
{
string now=pre;
for(j=0;j<pre.size();j++)
{
now[j]=vk[now[j]];
}
ins(now,i);
pre=now;
}
}
else if(tp==2)
{
f+=1;
f%=n;
}
else
{
scanf("%s",c);
if(ch(c,f))
{
printf("YES\n");
}
else printf("NO\n");
}
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGwgaW50CiNkZWZpbmUgbW8gMTAwMDAwMDAwNwoKbWFwPGxsLGxsPnRyaWVbMjZdWzI2XTsKbGwgc3o9MDsKY2hhciBwWzUwMDAwNV0sY1s1MDAwMDVdOwp2b2lkIGlucyhzdHJpbmcgcyxsbCByb290KQp7CiAgICBsbCBzdD0wOwogICAgZm9yKGxsIGk9MDtpPHMuc2l6ZSgpO2krKykKICAgIHsKICAgICAgICBsbCBjdXI9c1tpXS02NTsKICAgICAgICBpZih0cmllW3Jvb3RdW2N1cl1bc3RdPT0wKQogICAgICAgICAgICB0cmllW3Jvb3RdW2N1cl1bc3RdPSsrc3o7CiAgICAgICAgc3Q9dHJpZVtyb290XVtjdXJdW3N0XTsKICAgIH0KfQpsbCBjaChzdHJpbmcgcyxsbCByb290KQp7CiAgICBsbCBzdD0wOwogICAgZm9yKGxsIGk9MDtpPHMuc2l6ZSgpO2krKykKICAgIHsKICAgICAgICBsbCBjdXI9c1tpXS02NTsKICAgICAgICBpZih0cmllW3Jvb3RdW2N1cl1bc3RdPT0wKQogICAgICAgICAgICByZXR1cm4gMDsKICAgICAgICBzdD10cmllW3Jvb3RdW2N1cl1bc3RdOwogICAgfQogICAgcmV0dXJuIDE7Cn0KaW50IG1haW4oKQp7CiAgICBsbCBpLGosayxuLG0sdDsKICAgIHNjYW5mKCIlZCAlZCIsJm4sJnQpOwogICAgc2NhbmYoIiVzIixwKTsKICAgIG1hcDxjaGFyLGNoYXI+dms7CiAgICBmb3IoaT0wO2k8bjtpKyspCiAgICB7CiAgICAgICAgY2hhciBub3c9KGNoYXIpKGkrNjUpOwogICAgICAgIHZrW25vd109cFtpXTsKICAgIH0KICAgIGxsIGY9MDsKICAgIHdoaWxlKHQtLSkKICAgIHsKICAgICAgICBsbCB0cDsKICAgICAgICBzY2FuZigiJWQiLCZ0cCk7CiAgICAgICAgaWYodHA9PTEpCiAgICAgICAgewogICAgICAgICAgICBzY2FuZigiJXMiLGMpOwogICAgICAgICAgICBpbnMoYywwKTsKICAgICAgICAgICAgc3RyaW5nIHByZT1jOwogICAgICAgICAgICBmb3IoaT0xO2k8bjtpKyspCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHN0cmluZyBub3c9cHJlOwogICAgICAgICAgICAgICAgZm9yKGo9MDtqPHByZS5zaXplKCk7aisrKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIG5vd1tqXT12a1tub3dbal1dOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaW5zKG5vdyxpKTsKICAgICAgICAgICAgICAgIHByZT1ub3c7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZWxzZSBpZih0cD09MikKICAgICAgICB7CiAgICAgICAgICAgIGYrPTE7CiAgICAgICAgICAgIGYlPW47CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIHNjYW5mKCIlcyIsYyk7CiAgICAgICAgICAgIGlmKGNoKGMsZikpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHByaW50ZigiWUVTXG4iKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIHByaW50ZigiTk9cbiIpOwogICAgICAgIH0KICAgIH0KCn0K