// Arup Guha
// 2/3/2026
// Heritage problem on Kattis
// https://open.kattis.com/problems/heritage
// Added memoization to recursive solution so this runs fast enough.

import java.util.*;

public class heritage_memo {

	final public static long MOD = 1000000007L;

	public static int n;
	public static String name;
	public static String[] words;
	public static long[] numMeanings;
	
	public static long[] memo;
	
	public static void main(String[] args) {
	
		// Get # of words and name.
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		name = stdin.next();
		
		// Store strings here.
		words = new String[n];
		numMeanings = new long[n];
		for (int i=0; i<n; i++) {
			words[i] = stdin.next();
			numMeanings[i] = stdin.nextLong();
		}
		
		// Initialize memo table.
		memo = new long[name.length()+1];
		Arrays.fill(memo, -1);
		
		// Run it.
		System.out.println(go(0));
	}
	
	// Returns the answer for the string starting at index idx.
	public static long go(int idx) {
	
		// We're done.
		if (idx == name.length()) return 1;
		
		// See if we've done this before.
		if (memo[idx] != -1) return memo[idx];
		
		long res = 0;
		for (int i=0; i<n; i++) {
		
			// is words[i] a prefix of name[idx...]
			if (name.substring(idx).startsWith(words[i]))
				
				// Recurse from the index afer words[i] in the name string.
				res = (res + numMeanings[i]*go(idx + words[i].length()))%MOD;
		}
		
		// Store and return.
		return memo[idx] = res;
	}

}