// Arup Guha
// 2/3/2026
// Heritage problem on Kattis
// https://open.kattis.com/problems/heritage
// Converted memoized solution to DP.

import java.util.*;

public class heritage_dp {

	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[] dp;
	
	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();
		}
		
		// Store results here.
		dp = new long[name.length()+1];
		dp[name.length()] = 1;
		
		// Go backwards, solving for longer and longer suffixes.
		for (int i=dp.length-2; i>=0; i--) {
			
			// Initialize.
			dp[i] = 0;
			
			// See if each word is a prefix of this suffix.
			for (int j=0; j<n; j++)
				
				// It's a match.
				if (name.substring(i).startsWith(words[j]))
					
					// So our new position to build the rest from is i+words[j].length()
					// and we could have any of numMeanings[j] assigned to string words[j].
					dp[i] = (dp[i] + numMeanings[j]*dp[i+words[j].length()])%MOD;
		}
		
		// Print out result.
		System.out.println(dp[0]);
	}

}