#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define maxn 4000100
#define maxm 100100

int n, q, k, len, s0len, p, inv2, qlen;
int sum[30][maxm], nxt[maxn];
char s0[maxn], t[maxn], qstr[maxn], s[maxn];
vector<pair<int, int> > v[30];
const int mod = 1e9 + 7;
int qpow(int a, int b) {
    int ret = 1;
    while (b) {
        if (b & 1) {
            ret = 1LL * ret * a % mod;
        }
        b >>= 1;
        a = 1LL * a * a % mod;
    }
    return ret;
}

void init() {
    len = s0len = strlen(s0);
    memcpy(s, s0, s0len);
    while (len <= 1e6 && p < n) {
        s[len] = t[++p];
        memcpy(s + len + 1, s, len);
        len = 2 * len + 1;
    }
    memcpy(s + len + 1, s, len);
    int b = 1, slen = 2 * s0len + 1;
    inv2 = qpow(2, mod - 2);
    int invn2 = qpow(inv2, n - 1);
    for (int i = n; i >= 1; i--, b = 2LL * b % mod) {
        for (int j = 0; j < 26; j++) {
            sum[j][i] = sum[j][i + 1];
        }
        sum[t[i] - 'a'][i] = (sum[t[i] - 'a'][i + 1] + b) % mod;
    }
//    for (int i = 1; i <= n; i++) {
//        for (int j = 0; j < 26; j++) {
//            cout << (char) ('a' + j) << ' ' << i << ' ' << sum[j][i] << endl;
//        }
//    }
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 26; j++) {
            sum[j][i] = 1LL * sum[j][i] * invn2 % mod;
        }
    }
    for (int i = 1; i <= n; i++, slen = min(slen * 2 + 1, (int) 2e6)) {
        v[t[i] - 'a'].push_back(make_pair(slen, i));
    }
    for (int i = 0; i < 26; i++) {
        v[i].push_back(make_pair((int) 8e6, n + 1));
    }
}

void getnext() {
    int kk = 0;
    for (int i = 2; i <= qlen; i++) {
        while (kk && qstr[i] != qstr[kk + 1]) {
            kk = nxt[kk];
        }
        if (qstr[kk + 1] == qstr[i]) {
            kk++;
        }
        nxt[i] = kk;
    }
}

int kmp(char *str, int l, int r) {
    int kk = 0, ret = 0;
    for (int i = l; i <= r; i++) {
        while (kk > 0 && qstr[kk + 1] != str[i]) {
            kk = nxt[kk];
        }
        if (qstr[kk + 1] == str[i]) {
            kk++;
        }
        if (kk == qlen) {
            ret++;
            kk = nxt[kk];
        }
    }
    return ret;
}

int solve() {
    qlen = strlen(qstr + 1);
    int ret = 0;
    getnext();
    int kk = kmp(s0, 0, s0len - 1);
    ret = 1LL * kk * qpow(2, k) % mod;
//    cout << ret << "***********" << (qstr + 1) << endl;
    int llen = s0len * 2 + 1, p = 1;
    while (llen < qlen && p <= k) {
        llen = llen * 2 + 1;
        p++;
    }
    s[len] = t[p];
    if (p <= k && qlen > s0len) {
        int kkkk = kmp(s, len - llen / 2, len + llen / 2);
        ret = (ret + 1LL * kkkk * qpow(2, k - p) % mod) % mod;
//        cout << len << ' ' << llen << ' ' << kkkk << ' ' << len - llen / 2 + 1 << ' ' << len + llen / 2 - 1 << ' ' << p
//             << ' ' << ret << endl;
    }
    int lllen = (qlen > s0len) ? llen + 2 : 2 * qlen - 1;
    for (int i = 0; i < 26; i++) {
        int pp = lower_bound(v[i].begin(), v[i].end(), make_pair(lllen, 0)) - v[i].begin();
        auto aa = v[i][pp];
//        cout << (char) ('a' + i) << ' ' << aa.second << endl;
        if (aa.second > k) {
            continue;
        }
        s[len] = 'a' + i;
        int k2 = qpow(2, k - 1);
        int kkk = kmp(s, len - qlen + 1, len + qlen - 1);
        ret = (ret + 1LL * kkk * ((sum[i][aa.second] - sum[i][k + 1]) % mod + mod) % mod * k2 % mod) % mod;
//        cout << (char) ('a' + i) << ' ' << kkk << ' ' << aa.second << ' ' << ret << ' '
//             << 1LL * ((sum[i][aa.second] - sum[i][k + 1]) % mod + mod) % mod * k2 % mod << ' ' << qlen << ' ' << aa
//                     .first << endl;
    }
    return ret;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> q;
    cin >> s0;
    cin >> (t + 1);
    init();
    while (q--) {
        cin >> k >> (qstr + 1);
        cout << solve() << endl;
    }
    return 0;
}
