#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define setIO(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
#define closefile fclose(stdin), fclose(stdout)
#define m_p make_pair
#define sz(x) (int)x.size()
#define see(x) cerr << x << " "
#define seeln(x) cerr << x << endl
#define out(x) cerr << #x << " = " << x << " "
#define outln(x) cerr << #x << " = " << x << endl
#define outarr(x, l, r) {cerr<< #x"[" << l << " ~ " << r << "] = "; for (int _i = l; _i <= r; ++_i) cerr << x[_i] << " "; cerr << endl;}
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define gc() getchar()
//#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 21], *p1 = buf, *p2 = buf;
template <class T> void read(T &x)
{
    x = 0; int c = gc(); int flag = 0;
    while (c < '0' || c > '9') flag |= (c == '-'), c = gc();
    while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) +(c ^ 48), c = gc();
    if (flag) x = -x;
}
template <class T> T _max(T a, T b){return b < a ? a : b;}
template <class T> T _min(T a, T b){return a < b ? a : b;}
template <class T> bool checkmax(T &a, T b){return a < b ? a = b, 1 : 0;}
template <class T> bool checkmin(T &a, T b){return b < a ? a = b, 1 : 0;}
const int N = 400005, M = 1000005, mod = 1000000000 + 7, inv2 = (mod + 1) / 2;
void add(int &a, int b){a += b; (a >= mod) && (a -= mod);}
void sub(int &a, int b){a -= b; (a < 0) && (a += mod);}
void mul(int &a, int b){a = (ll)a * b % mod;}
int Add(int a, int b){a += b; return a >= mod ? a - mod : a;}
int Sub(int a, int b){a -= b; return a < 0 ? a + mod : a;}
int Mul(int a, int b){return (ll)a * b % mod;}
int qpow(int a, int b){int ans = 1; while (b) {if (b & 1) ans = (ll)ans * a % mod; a = (ll)a * a % mod; b >>= 1;} return ans;}

char t[N], b[M];
string s0;
int n, q, m;
int csp[M];
int g[26];
int pw2[M], ipw2[M];
int suf[N][26];
int hcy = 0;
void init()
{
	read(n); read(q);
	char tmp[104];
	scanf("%s%s", tmp, t + 1);
	s0 = tmp;
	pw2[0] = 1; for (int i = 1; i <= 1000000; ++i) pw2[i] = 2LL * pw2[i - 1] % mod;
	ipw2[0] = 1; for (int i = 1; i <= 1000000; ++i) ipw2[i] = (ll)inv2 * ipw2[i - 1] % mod;
	for (int i = 1; i <= n; ++i)
	{
		memcpy(suf[i], suf[i - 1], sizeof suf[i]);
		add(suf[i][t[i] - 'a'], ipw2[i]);
	}
}

void get_csp(char *s, int n)
{
	int i = 1, j = 0;
	for (; i < n; ++i)
	{
		while (j && s[i] != s[j]) j = csp[j - 1];
		if (s[i] == s[j]) ++j, csp[i] = j;
		else csp[i] = 0;
	}
}

int kmp(string s, char *t, int n, int m)
{
	int i = 0, j = 0, occ = 0;
	for (; i < n; ++i)
	{
		while (j && s[i] != t[j]) j = csp[j - 1];
		if (s[i] == t[j]) ++j;
		if (j == m)
		{
			++occ;
			j = csp[j - 1];
		}
	}
	return occ;
}

int calc(int k)
{
	string s = s0; int now = 1;
	if (sz(s0) < m)
	{
		for (int i = 1; i < k; ++i) 
		{
			s = s + t[i] + s;
			if (sz(s) >= m) {now = i + 1; break;}
		}
	}
	int w = sz(s);
	if (w < m) return 0;
	get_csp(b, m);
	int F = kmp(s, b, w, m);
	if (k < now) return F;
	string ss = s.substr(sz(s) - m + 1) + '0' + s.substr(0, m - 1);
	for (int i = 0; i < 26; ++i)
	{
		ss[m - 1] = 'a' + i;
		g[i] = kmp(ss, b, m + m - 1, m);
	}
	mul(F, pw2[k - now]);
	int o = 0;
	for (int i = 0; i < 26; ++i)
	{
		add(o, Mul(g[i], Sub(suf[k - 1][i], suf[now - 1][i])));
	}
	add(F, Mul(o, pw2[k - 1]));
	return F;
}

void solve()
{
	int k;
	vector<int> v;
	for (int i = 1; i <= q; ++i)
	{ 
		read(k); ++k; scanf("%s", b);
		m = strlen(b);
		printf("%d\n", calc(k));
	}
}

int main()
{
	//setIO("");
	init();
	solve();
	return 0;
}
