#include <cstdio>
#include <cctype>
#include <vector>
#include <algorithm>

template <typename Tp>
void read(Tp &res){
	static char ch; ch = getchar(), res = 0;
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) res = res * 10 + ch - 48, ch = getchar();
}

int read(char *s){
	static char ch; static int len;
	ch = getchar(), len = 0;
	while(!isalpha(ch)) ch = getchar();
	while(isalpha(ch)) *(s++) = ch, ch = getchar(), ++len;
	return len;
}

typedef long long ll;
const int maxn = 1e5 + 19, maxl = 1e6 + 19, mod = 1e9 + 7;

int n, q, L, ind, m;
char s[maxl << 1], t[maxn], w[maxl << 1];

struct Str{
	int len, q, ans, beg;
	char *s;
	std::vector<int> next, inext;
	char &operator[](const int &x){return s[x - 1]; }
	const char &operator[](const int &x)const{return s[x - 1]; }
	void init(void){
		next.resize(len + 1), inext.resize(len + 1);
		for(int i = 2, j = 0; i <= len; ++i){
			while(j && this->operator[](j + 1) != this->operator[](i)) j = next[j];
			if(this->operator[](j + 1) == this->operator[](i)) ++j;
			next[i] = j;
		}
		for(int i = 2, j = 0; i <= len; ++i){
			while(j && this->operator[](len - j) != this->operator[](len - i + 1)) j = inext[j];
			if(this->operator[](len - j) == this->operator[](len - i + 1)) ++j;
			inext[i] = j;
		}
	}
}str[maxl];

int cmp(const Str &str){
	int n = str.len, res = 0;
	std::vector<int>::const_iterator next = str.next.cbegin();
	for(int i = 1, j = 0; i <= L; ++i){
		while(j && str[j + 1] != s[i]) j = next[j];
		if(str[j + 1] == s[i]) ++j;
		if(j == n) j = next[j], ++res;
	}
	return res;
}

std::vector<int> mask;
int cnt[maxn][26], shift[maxn];

int solve(const Str &str){
	if(str.q < str.beg) return 0;
	int res = (ll)str.ans * shift[str.q - str.beg] % mod, n = str.len, j = 0;
	static bool pre[maxl], suf[maxl];
	static int w[26];
	for(int i = 0; i < 26; ++i) w[i] = 0;
	for(int i = 1; i <= n + 1; ++i) pre[i] = suf[i] = 0;
	pre[0] = 1, suf[n + 1] = 1;
	std::vector<int>::const_iterator next = str.next.begin(), inext = str.inext.begin();
	for(int i = L - n + 2; i <= L; ++i){
		while(j && str[j + 1] != s[i]) j = next[j];
		if(str[j + 1] == s[i]) ++j;
	}
	while(j) pre[j] = 1, j = next[j];
	for(int i = L - n + 2; i <= L; ++i){
		while(j && str[n - j] != s[L - i + 1]) j = inext[j];
		if(str[n - j] == s[L - i + 1]) ++j;
	}
	while(j) suf[n - j + 1] = 1, j = inext[j];
//	for(int i = 1; i <= str.len; ++i) putchar(str[i]);
//	puts(":");
//	for(int i = 1; i <= n; ++i) printf("%d", (int)pre[i]);
//	puts("");
//	for(int i = 1; i <= n; ++i) printf("%d", (int)suf[i]);
//	puts("");
	for(int i = 1; i <= n; ++i) if(pre[i - 1] && suf[i + 1]) ++w[str[i] - 'a'];//, printf("%d paired\n", i);
	for(int i = 0; i < 26; ++i) if(w[i]){
//		printf("%c %d\n", 'a' + (char)i, w[i]);
		res = (res + (cnt[str.q][i] - (ll)cnt[str.beg][i] * shift[str.q - str.beg]) % mod * w[i]) % mod;
	}
	return (res + mod) % mod;
}

int main(){
	read(n), read(q), L = read(s + 1), read(t + 1);
	shift[0] = 1;
	for(int i = 1; i <= n; ++i) shift[i] = shift[i - 1] * 2 % mod;
	mask.resize(q);
	for(int i = 0, j = 1; i < q; ++i){
		mask[i] = i, str[i].s = w + j;
		read(str[i].q), j += (str[i].len = read(w + j)) + 1, str[i].init(), str[i].beg = 1e9;
	}
	std::sort(mask.begin(), mask.end(), [](const int &a, const int &b){
		return str[a].len > str[b].len;
	});
	while(!mask.empty() && str[mask.back()].len <= L){
		str[mask.back()].beg = ind;
		str[mask.back()].ans = cmp(str[mask.back()]);
		mask.pop_back();
	}
	while(ind < n && !mask.empty()){
		++ind;
		for(int i = 0; i < 26; ++i) cnt[ind][i] = cnt[ind - 1][i] * 2 % mod;
		++cnt[ind][t[ind] - 'a'];
		for(int i = L + 2; i <= L + L + 1; ++i) s[i] = s[i - L - 1];
		s[L + 1] = t[ind];
		L = L * 2 + 1;
		while(!mask.empty() && str[mask.back()].len <= L){
			str[mask.back()].beg = ind;
			str[mask.back()].ans = cmp(str[mask.back()]);
			mask.pop_back();
		}
	}
	while(ind < n){
		++ind;
		for(int i = 0; i < 26; ++i) cnt[ind][i] = cnt[ind - 1][i] * 2 % mod;
		++cnt[ind][t[ind] - 'a'];
	}
	for(int i = 0; i < q; ++i) printf("%d\n", solve(str[i]));
	return 0;
}