#include<cstdio>
#include<iostream>
#include<iomanip>
#include<set>
#include<map>
#include<vector>
#include<deque>
#include<utility>
#include<algorithm>
#include<cmath>


using namespace std;


typedef long long int lli;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;



const int MAXL = 25;
const int MAXW = 1000001;
const int ALPHABET = 26;
const lli MOD = 1000000007ll;


int N, Q, K;
string T, W;
string S[MAXL];
lli twoPow[MAXW];
lli preSum[ALPHABET][MAXW];


vi pi(const string& s) {
    vi p(sz(s));
    rep(i,1,sz(s)) {
        int g = p[i-1];
        while (g && s[i] != s[g]) g = p[g-1];
        p[i] = g + (s[i] == s[g]);
    }
    return p;
}

int match(const string& s, const string& pat) {
    vi p = pi(pat + '\0' + s), res;
    int ret = 0;
    rep(i,sz(p)-sz(s),sz(p))
        if (p[i] == sz(pat)) ret++;
    return ret;
}


void solve() {

    int initPoint = 0;
    while ((int)S[initPoint].size() < (int)W.size()) {
        initPoint++;
    }

    if (initPoint > K) {
        cout << "0\n";
        return;
    }

    //cerr << "\nINIT STRING = " << S[initPoint] << "\n";

    set<int> middle_pref;
    set<int> middle_suf;

    {
        string s_pref = W + "$" + S[initPoint];
        vi pi_pref = pi(s_pref);
        int at = (int)s_pref.size();
        at = pi_pref[at-1];
        while (at > 0) {
            middle_pref.insert(at);
            at = pi_pref[at-1];
        }
        middle_pref.insert(at);
    }

    {
        string s_suf = S[initPoint] + "$" + W;
        vi pi_suf = pi(s_suf);
        int at = (int)s_suf.size();
        at = pi_suf[at-1];
        while (at > 0) {
            middle_suf.insert(at);
            at = pi_suf[at-1];
        }
        middle_suf.insert(at);
    }

    lli ans = ((lli)match(S[initPoint], W) * twoPow[K-initPoint]) % MOD;

    //cerr << "\n\nPRINTING pref\n";
    for (auto pref : middle_pref) {
        //cerr << pref << "\n";
        if (middle_suf.count((int)W.size() - pref - 1) == 0) {
            continue;
        }

        char ch = W[pref];

        lli subtract = ((preSum[(int)(ch-'a')][initPoint] * twoPow[K-initPoint]) % MOD);
        lli add = preSum[(int)(ch-'a')][K]; 
        ans = (((ans + add - subtract) % MOD) + MOD) % MOD;
    }

    cout << ans << "\n";
}


int main() {

    ios::sync_with_stdio(0);
    cin.tie(0); 
    cout.tie(0); 
    cerr.tie(0); 


    cin >> N >> Q;
    cin >> S[0] >> T;

    {
        int i = 0;
        while ((int)S[i].size() < MAXW) {
            S[i+1] = S[i] + T[i] + S[i];
            i++;
        }
    }

    {
        twoPow[0] = 1;
        for (int i = 1 ; i < MAXW ; i++) {
            twoPow[i] = (twoPow[i-1]*2) % MOD;
        }

        for(int i = 0 ; i  < ALPHABET ; i++) {
            for (int j = 1 ; j <= N ; j++) {
                preSum[i][j] = (preSum[i][j-1]*2) % MOD;
                if (T[j-1] == (char)((int)('a')+i)) {
                    preSum[i][j] = (preSum[i][j]+1) % MOD; 
                }
            }
        }
    }

    for (int q = 1 ; q <= Q; q++) {
        cin >> K >> W;
        solve();
    }



    



    return 0;
}










