#include <bits/stdc++.h>

using pii = std::pair <int, int>;

std::vector<pii> pbs;

struct Hash{
    int moder, base;
    std::vector <int> power;
    std::vector <int> hash;

    Hash(int moder, int base, const char *s, int n):moder(moder), base(base), power(n + 1), hash(n + 1){
        hash[0] = 0, power[0] = 1;
        for (int i = 1; i <= n; ++ i){
            hash[i] = (1ll * base * hash[i - 1] + s[i - 1]) % moder;
            power[i] = 1ll * power[i - 1] * base % moder;
        }
    }

    int query(int l, int r){
        int ret = (hash[r + 1] - 1ll * power[r - l + 1] * hash[l]) % moder;
        ret += ret < 0 ? moder : 0;
        return ret;
    }
};

struct Hasher{
    std::vector<Hash> hashes1, hashes2;

    Hasher(const std::vector<pii> &pbs, char *s, char *t){
        int n = strlen(s), m = strlen(t);
        for (auto pb : pbs){
            hashes1.emplace_back(pb.first, pb.second, s, n);
            hashes2.emplace_back(pb.first, pb.second, t, m);
        }
    }

    bool query(int l1, int r1, int l2, int r2){
        int sz = hashes1.size();
        for (int i = 0; i < sz; ++ i){
            if (hashes1[i].query(l1, r1) != hashes2[i].query(l2, r2)){
                return false;
            }
        }
        return true;
    }
};

const int N = 2000010;
const int M = 100010;
const int K = 30;
const int moder = int(1e9) + 7;

char s[N], t[N];
char tmp[N], query[N];
bool prefix[N], suffix[N];
int pref[M][K];
int power[N];

int build(){
    Hasher hasher(pbs, tmp, query);
    int n = strlen(tmp);
    int m = strlen(query);
    int cnt = 0;
    for (int i = 0; i < n; ++ i){
        int r = i + m - 1;
        if (r >= n){
            break;
        }
        cnt += hasher.query(i, r, 0, m - 1);
    }
    prefix[0] = suffix[0] = true;
    for (int i = 1; i <= m; ++ i){
        int l1 = 0, r1 = i - 1;
        int l2 = m - i, r2 = m - 1;
        suffix[i] = hasher.query(l1, r1, l2, r2);
        l1 = n - i, r1 = n - 1;
        l2 = 0, r2 = i - 1;
        prefix[i] = hasher.query(l1, r1, l2, r2);
    }
    return cnt;
}

void add(int &u, int v){
    u += v;
    u -= u >= moder ? moder : 0;
}

int main(){
    std::vector<int> primes = {
        1001452733,
        1001452759,
        1001452787,
        1001452789,
        1001452871,
        1001452897,
        1001452937,
        1001452957,
        1001452981,
        1001452993,
        1001452999,
        1001453021,
        1001453029,
        1001453041,
        1001453069,
        1001453081
    };

    std::vector<int> bases = {
        37,
        41,
        43,
        47,
        53,
        59,
        61,
        67,
        71,
        73,
        79,
        83,
        89,
        97,
        101,
        103,
    };

    std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
    std::shuffle(primes.begin(), primes.end(), rnd);
    std::shuffle(bases.begin(), bases.end(), rnd);

    pbs = {{primes[0], bases[0]}, {primes[1], bases[1]}};

    power[0] = 1;
    for (int i = 1; i < N; ++ i){
        power[i] = 2 * power[i - 1] % moder;
    }

    int n, q;
    scanf("%d%d", &n, &q);
    scanf("%s%s", s, t);
    int lent = strlen(t);
    for (int i = 0; i < lent; ++ i){
        for (int j = 0; j < K; ++ j){
            pref[i + 1][j] = 2ll * pref[i][j] % moder;
        }
        add(pref[i + 1][t[i] - 'a'], 1);
    }
    while (q --){
        int end;
        scanf("%d%s", &end, query);
        int m = strlen(query);
        std::string str = s;
        int cur = 0;
        while (cur < end && str.size() < m){
            str += t[cur] + str;
            ++ cur;
        }
        if (str.size() < m){
            puts("0");
            continue;
        }
        strcpy(tmp, str.c_str());
        int cnt = build();
        int ans = 1ll * power[end - cur] * cnt % moder;
        for (int i = 0; i < m; ++ i){
            if (prefix[i] && suffix[m - 1 - i]){
                int value = (pref[end][query[i] - 'a'] - 1ll * power[end - cur] * pref[cur][query[i] - 'a']) % moder;
                value += value < 0 ? moder : 0;
                add(ans, value);
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

/*
4 1
aba
bbac
3 ab

2 7
a
bc
2 a
2 b
2 c
2 ab
2 ba
2 aca
1 aca

1 4
awag
t
0 a
0 b
0 w
0 g

7 1
cabbcac
cabccca
7 acb
 */
