// Author : heyuhhh
// Created Time : 2021/01/05 11:39:55
#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 2e6 + 5, MOD = 1e9 + 7, INV = (MOD + 1) / 2;

inline int add(int x, int y) {
    return x + y >= MOD ? x + y - MOD : x + y;
}
inline int dec(int x, int y) {
    return x - y < 0 ? x - y + MOD : x - y;
}
inline int mul(int x, int y) {
    return 1ll * x * y % MOD;
}

int pow2[N], inv2[N];
void init() {
    pow2[0] = inv2[0] = 1;
    for (int i = 1; i < N; i++) {
        pow2[i] = mul(pow2[i - 1], 2);
        inv2[i] = mul(inv2[i - 1], INV);
    }
}

typedef unsigned long long ull;
template <unsigned mod, unsigned base>
struct rolling_hash {
    unsigned int pg[N], val[N]; // val:1,2...n
    rolling_hash() {
        pg[0] = 1;
        for(int i = 1; i < N; i++) pg[i] = 1ull * pg[i - 1] * base % mod;
        val[0] = 0;
    }
    void build(const char *str) {
        for(int i = 0; str[i]; i++) {
            val[i + 1] = (str[i] + 1ull * val[i] * base) % mod;
        }
    }
    unsigned int operator() (int l, int r) {
        ++r; // 
        return (val[r] - 1ull * val[l] * pg[r - l] % mod + mod) % mod;
    }
};
struct dm_hasher {
    //str:0,1...len-1
    rolling_hash<997137961, 753> h1;
    rolling_hash<1003911991, 467> h2;
    void build(const char *str) {
        h1.build(str); h2.build(str);
    }
    ull operator() (int l, int r) {
        return ull(h1(l, r)) << 32 | h2(l, r);
    }
}hasher, hasher2;

void run() {
    int n, q;
    cin >> n >> q;
    string s0, t;
    cin >> s0 >> t;
    vector<vector<int>> pos(26);
    for (int i = 0; i < n; i++) {
        pos[t[i] - 'a'].emplace_back(i);
    }

    vector<int> c(n);
    vector<int> last(26);
    for (int i = 0; i < 26; i++) {
        for (int j = sz(pos[i]) - 1; j >= 0; j--) {
            if (j == sz(pos[i]) - 1) {
                c[pos[i][j]] = 1;
                last[i] = pos[i][j];
            } else {
                c[pos[i][j]] = add(c[pos[i][j + 1]], pow2[last[i] - pos[i][j]]);
            }
        }
    }
    while (q--) {
        int id;
        string s;
        cin >> id >> s;
        int len = s.length();
        int k;
        string res = s0;
        int ans = 0;
        for (int i = 0; i <= id; i++) {
            if (res.length() >= len) {
                k = i;
                break;
            }
            if (i < id) res += t[i] + res;
        }
        if (res.length() < len) {
            cout << 0 << '\n';
            continue;
        }
        hasher.build(res.c_str());
        hasher2.build(s.c_str());
        ull val = hasher2(0, len - 1);
        int resLen = res.length();
        for (int i = 0; i + len - 1 < resLen; i++) {
            int j = i + len - 1;
            if (hasher(i, j) == val) {
                ++ans;
            }
        }
        ans = mul(ans, pow2[id - k]);
        vector<int> f(26);
        for (int j = 1; j < len; j++) {
            if (hasher(resLen - j, resLen - 1) == hasher2(0, j - 1)
                && hasher(0, len - j - 2) == hasher2(j + 1, len - 1)
                ) {
                    ++f[s[j] - 'a'];
                }
        }
        if (hasher(0, len - 2) == hasher2(1, len - 1)) {
            ++f[s[0] - 'a'];
        }
        // add t[k]....t[id - 1]
        for (int i = 0; i < 26; i++) if (f[i]) {
            int lAt = lower_bound(all(pos[i]), k) - pos[i].begin();
            int rAt = lower_bound(all(pos[i]), id) - pos[i].begin() - 1;
            int res = 0;
            if (lAt == sz(pos[i])) continue;
            if (rAt == sz(pos[i]) - 1) {
                res = mul(f[i], mul(c[pos[i][lAt]], pow2[id - 1 - last[i]]));
            } else {
                int tmp = dec(c[pos[i][lAt]], c[pos[i][rAt + 1]]);
                res = mul(f[i], mul(tmp, inv2[last[i] - id + 1]));
            }
            ans = add(ans, res);
        }
        cout << ans << '\n';
    }
}
int main() {
#ifdef Local
    freopen("input.in", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    init();
    run();
    return 0;
}
### Prompt

Develop a solution in cpp to the problem described below:

Whoso in ignorance draws near to them and hears the Sirens' voice, he nevermore returns.

Homer, Odyssey

In the times of Jason and the Argonauts, it was well known that sirens use the sound of their songs to lure sailors into their demise. Yet only a few knew that every time sirens call a sailor by his name, his will weakens, making him more vulnerable. 

For the purpose of this problem, both siren songs and names of the sailors will be represented as strings of lowercase English letters. The more times the sailor's name occurs as a contiguous substring of the song, the greater danger he is in.

Jason found out that sirens can sing one of the n+1 songs, which have the following structure: let s_i (0 ≤ i ≤ n) be the i-th song and t be a string of length n, then for every i < n: s_{i+1} = s_i t_i s_i. In other words i+1-st song is the concatenation of i-th song, i-th letter (0-indexed) of t and the i-th song. 

Fortunately, he also knows s_0 and t. Jason wonders how many times a sailor's name is mentioned in a particular song. Answer q queries: given the sailor's name (w) and the index of a song (i) output the number of occurrences of w in s_i as a substring. As this number can be quite large, output its remainder modulo 10^9+7.

Input

In the first line of input there are two integers n, q (  1 ≤ n, q ≤ 10^5) meaning that there are n+1 songs and q queries. In the next two lines strings s_0 and t follow (1 ≤ |s_0| ≤ 100, |t| = n). 

Next q lines describe the queries; each one contains an integer k ( 0 ≤ k ≤ n), the index of the song sung by the sirens, and a non-empty string w, which is the name of a sailor. All strings in this problem consist only of lowercase English letters, and the sum of lengths of sailors' names does not exceed 10^6.

Output

Output q lines, i-th of them should contain the remainder modulo 10^9+7 of the number of occurrences of w in s_k.

Examples

Input


3 3
aa
bcd
2 aba
3 ca
3 aa


Output


2
2
8


Input


4 5
aba
bbac
1 a
3 baca
3 ab
2 bab
4 aba


Output


4
0
14
6
28

Note

In the first example songs of the sirens are as follows: 

  * Song 0: aa
  * Song 1: aabaa
  * Song 2: aabaacaabaa
  * Song 3: aabaacaabaadaabaacaabaa

### Response

```cpp
// Author : heyuhhh
// Created Time : 2021/01/05 11:39:55
#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 2e6 + 5, MOD = 1e9 + 7, INV = (MOD + 1) / 2;

inline int add(int x, int y) {
    return x + y >= MOD ? x + y - MOD : x + y;
}
inline int dec(int x, int y) {
    return x - y < 0 ? x - y + MOD : x - y;
}
inline int mul(int x, int y) {
    return 1ll * x * y % MOD;
}

int pow2[N], inv2[N];
void init() {
    pow2[0] = inv2[0] = 1;
    for (int i = 1; i < N; i++) {
        pow2[i] = mul(pow2[i - 1], 2);
        inv2[i] = mul(inv2[i - 1], INV);
    }
}

typedef unsigned long long ull;
template <unsigned mod, unsigned base>
struct rolling_hash {
    unsigned int pg[N], val[N]; // val:1,2...n
    rolling_hash() {
        pg[0] = 1;
        for(int i = 1; i < N; i++) pg[i] = 1ull * pg[i - 1] * base % mod;
        val[0] = 0;
    }
    void build(const char *str) {
        for(int i = 0; str[i]; i++) {
            val[i + 1] = (str[i] + 1ull * val[i] * base) % mod;
        }
    }
    unsigned int operator() (int l, int r) {
        ++r; // 
        return (val[r] - 1ull * val[l] * pg[r - l] % mod + mod) % mod;
    }
};
struct dm_hasher {
    //str:0,1...len-1
    rolling_hash<997137961, 753> h1;
    rolling_hash<1003911991, 467> h2;
    void build(const char *str) {
        h1.build(str); h2.build(str);
    }
    ull operator() (int l, int r) {
        return ull(h1(l, r)) << 32 | h2(l, r);
    }
}hasher, hasher2;

void run() {
    int n, q;
    cin >> n >> q;
    string s0, t;
    cin >> s0 >> t;
    vector<vector<int>> pos(26);
    for (int i = 0; i < n; i++) {
        pos[t[i] - 'a'].emplace_back(i);
    }

    vector<int> c(n);
    vector<int> last(26);
    for (int i = 0; i < 26; i++) {
        for (int j = sz(pos[i]) - 1; j >= 0; j--) {
            if (j == sz(pos[i]) - 1) {
                c[pos[i][j]] = 1;
                last[i] = pos[i][j];
            } else {
                c[pos[i][j]] = add(c[pos[i][j + 1]], pow2[last[i] - pos[i][j]]);
            }
        }
    }
    while (q--) {
        int id;
        string s;
        cin >> id >> s;
        int len = s.length();
        int k;
        string res = s0;
        int ans = 0;
        for (int i = 0; i <= id; i++) {
            if (res.length() >= len) {
                k = i;
                break;
            }
            if (i < id) res += t[i] + res;
        }
        if (res.length() < len) {
            cout << 0 << '\n';
            continue;
        }
        hasher.build(res.c_str());
        hasher2.build(s.c_str());
        ull val = hasher2(0, len - 1);
        int resLen = res.length();
        for (int i = 0; i + len - 1 < resLen; i++) {
            int j = i + len - 1;
            if (hasher(i, j) == val) {
                ++ans;
            }
        }
        ans = mul(ans, pow2[id - k]);
        vector<int> f(26);
        for (int j = 1; j < len; j++) {
            if (hasher(resLen - j, resLen - 1) == hasher2(0, j - 1)
                && hasher(0, len - j - 2) == hasher2(j + 1, len - 1)
                ) {
                    ++f[s[j] - 'a'];
                }
        }
        if (hasher(0, len - 2) == hasher2(1, len - 1)) {
            ++f[s[0] - 'a'];
        }
        // add t[k]....t[id - 1]
        for (int i = 0; i < 26; i++) if (f[i]) {
            int lAt = lower_bound(all(pos[i]), k) - pos[i].begin();
            int rAt = lower_bound(all(pos[i]), id) - pos[i].begin() - 1;
            int res = 0;
            if (lAt == sz(pos[i])) continue;
            if (rAt == sz(pos[i]) - 1) {
                res = mul(f[i], mul(c[pos[i][lAt]], pow2[id - 1 - last[i]]));
            } else {
                int tmp = dec(c[pos[i][lAt]], c[pos[i][rAt + 1]]);
                res = mul(f[i], mul(tmp, inv2[last[i] - id + 1]));
            }
            ans = add(ans, res);
        }
        cout << ans << '\n';
    }
}
int main() {
#ifdef Local
    freopen("input.in", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    init();
    run();
    return 0;
}
```