#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const ll MOD = 1e9+7;
const int N = 3000005;
ll power(ll x,ll mi,ll mod = MOD)
{
    ll s1=1LL,s2=x%mod,m=mi;
    for (;m;m>>=1) {if (m&1) s1=s1*s2%mod;s2=s2*s2%mod;}
    return s1;
}
inline ll getinv(ll x,ll mod = MOD) {return power(x,mod - 2);};
string st[N],t,q;
ll len[N],mi2[N];
int nxt[N];
int n,m,k;
int findc(const string & st,int x,char ch)
{
    if (st[x]==ch) return x+1;
    if (!x) return x;
    return findc(st,nxt[x],ch);
}
ll calc(const string & t,const string & s)
{
    ll cnt=0;
    nxt[1]=0;
    for (int i=2;i<=t.size();++i) nxt[i]=findc(t,nxt[i-1],t[i-1]);
    for (int now=0,i=0;i<s.size();++i)
    {
        now=findc(t,now,s[i]);
        if (now==t.size()) ++cnt;
    }
    return cnt;
}
ll inv2=power(2,MOD-2);
int sum[100005][26];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    cin>>st[0]>>t;
    len[0]=st[0].size();
    mi2[0]=1;
    for (int i=1;i<=n;++i)
    {
        memcpy(sum[i],sum[i-1],sizeof sum[i]);
        (sum[i][t[i-1]-'a']+=power(inv2,i))%=MOD;
        mi2[i]=mi2[i-1]*2%MOD;
        if (len[i-1]>1000000)
        {
            len[i]=len[i-1];
        }else
        {
            len[i]=len[i-1]*2+1;
            st[i]=st[i-1]+t[i-1]+st[i-1];
        }
    }
    for (int cas=1;cas<=m;++cas)
    {
        cin>>k>>q;
        if (q.size()>len[k]) {cout<<0<<endl;continue;};
        int id=0;for (;len[id]<q.size();) ++id;
        ll ans=0,cntid=calc(q,st[id]);
        if (id<=k) ans=(ans+cntid*mi2[k-id])%MOD;
        if (id+1<=k)
        {
            string ss=st[id]+'a'+st[id];
            for (char ch='a';ch<='z';++ch)
            {
                ss[st[id].size()]=ch;
                ll tt=(calc(q,ss)-cntid*2);
                ans=(ans+tt*(sum[k][ch-'a']-sum[id][ch-'a'])%MOD*mi2[k]%MOD)%MOD;
            }
        }
        ans=(ans%MOD+MOD)%MOD;//////
        cout<<ans<<endl;//
    }
    return 0;
}