#include <bits/stdc++.h>

#define PI 3.14159265358979323846264338327950288419
#define mod 1000000007

using namespace std;

const int MAXLEN = 1000000;


int pow2[1000005];

int n, q;
int len[22], lim = 0;
string s[22], t;

int k;
string query;

int fail[2000005];
bool pref[2000005], suff[2000005];

int pre_joint[100005][26];
int joint[26];

void build_fail(string str) {
	fail[0] = -1;
	for (int i = 1; i < str.length(); i++) {
		fail[i] = fail[i - 1];
		while(fail[i] != -1 && str[i] != str[fail[i] + 1]) {
			fail[i] = fail[fail[i]];
		}
		if (str[i] == str[fail[i] + 1])
			fail[i]++;
	}
}

pair<int, int> find_match(string str, string tar) {
	int match = 0;
	int pos = -1;
	for (int i = 0; i < str.length(); i++) {
		while (pos != -1 && str[i] != tar[pos + 1]) {
			pos = fail[pos];
		}
		if (str[i] == tar[pos + 1]) {
			pos++;
			if (pos == tar.length() - 1) {
				match++;
				pos = fail[pos];
			}
		}
	}
	return {match, pos};
}


int main(){
	pow2[0] = 1;
	for (int i = 1; i <= 1000000; i++) {
		pow2[i] = pow2[i - 1] * 2 % mod;
	}
	
	ios::sync_with_stdio(false);
	
	cin >> n >> q;
	cin >> s[0] >> t;
	len[0] = s[0].length();
	for (int i = 0; len[i] <= MAXLEN; i++) {
		len[i + 1] = 2 * len[i] + 1;
		s[i + 1] = s[i] + t[i] + s[i];
		lim++;
	}
	
	// pre_joint[i][j] = number of occurrences of character j as "joint" in s[i]
	// with s[lim] as a block
	for (int i = lim + 1; i <= n; i++) {
		for (int j = 0; j < 26; j++) {
			pre_joint[i][j] = 2 * pre_joint[i - 1][j] % mod;
		}
		pre_joint[i][t[i - 1] - 'a']++;
	}
	
	while (q--) {
		cin >> k >> query;
		if (k <= lim && query.length() > len[k]) {
			printf("0\n");
			continue;
		}
		
		int tj = -1;
		for (int j = 0; j <= lim; j++) {
			if(len[j] >= query.length()){
				tj = j;
				break;
			}
		}
		
		assert(tj != -1 && tj <= k);
		
		// first count # occurrences in s[tj]
		// then count # occurrences in s[tj] + C + s[tj] for each character C
		// this can be done by matching prefix / suffix
		build_fail(query);
		pair<int, int> placeholder = find_match(s[tj], query);
		int occ_within = placeholder.first;
		int pos = placeholder.second;
		
		// within
		long long ans1 = 1LL * occ_within * pow2[k - tj] % mod;
		
		// across
		for (int i = 0; i < query.length(); i++) {
			pref[i] = false;
			suff[i] = false;
		}
		
		while (pos != -1) {
			pref[pos] = true;
			pos = fail[pos];
		}
		
		reverse(query.begin(), query.end());
		reverse(s[tj].begin(), s[tj].end());
		build_fail(query);
		pos = find_match(s[tj], query).second;
		reverse(query.begin(), query.end());
		reverse(s[tj].begin(), s[tj].end());
		
		while (pos != -1) {
			suff[query.length() - 1 - pos] = true;
			pos = fail[pos];
		}
/*
		cout << s[tj] << endl;
		for (int i = 0; i < query.length(); i++) {
			printf("%d", pref[i]);
		}
		puts("");
		for (int i = 0; i < query.length(); i++) {
			printf("%d", suff[i]);
		}
		puts("");
*/
		// calculate joint[]
		for (int i = 0; i < 26; i++) {
			joint[i] = pre_joint[k][i];
		}
		
		for (int i = tj + 1; i <= k && i <= lim; i++) {
			joint[t[i - 1] - 'a'] = (joint[t[i - 1] - 'a'] + pow2[k - i]) % mod;
		}
		
		long long ans2 = 0;
		for (int i = 0; i < query.length(); i++) {
			if (i > 0 && !pref[i - 1])
				continue;
			if (i + 1 < query.length() && !suff[i + 1])
				continue;
			ans2 = (ans2 + joint[query[i] - 'a']) % mod;
		}
		
		printf("%lld\n", (ans1 + ans2) % mod);
	}
	return 0;
}
