import java.io.*;
import java.math.BigInteger;
import java.util.*;

 
public class Main{
	/*
	 * use Integer for sorting
	 * avoid object comparison
	 * NEVER APPEND A STRING 
	 * 
	 */
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static long mod = (long) (1e9+7);
	static long cf = 998244353;
    static final long MAX = (long) 1e8;
    public static List<Integer>[] edges;
    public static int[][] parent;
    public static long[] fac;
    public static int N = 400000+200;
    public static int x = 0;
    public static boolean[] visited;
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		  int t = sc.nextInt();
		  
		 
		    while(t-->0) {
		    	int x = sc.nextInt();
		    	long len = -1;
		    	StringBuilder sb = new StringBuilder(sc.next());
		    	for(int i=0;i<x;++i) {
		    		
		    		if(sb.length() < x) {
		    		int till = sb.length();
		    		for(int j=0;j<(sb.charAt(i)-'0')-1;++j) {
		    			for(int k=i+1;k<till;++k)
		    			sb.append(sb.charAt(k));
		    		
		    		}			
		    		
		    		}else {
		    			if(len == -1) len = sb.length()-i-1;
		    			else len = (len-1+mod)%mod;
		    			long freq = sb.charAt(i)-'0';
		    			len = (freq*len)%mod;
		    		}
		    	}
		    	out.println((len+x)%mod);
		    	
		    	
		    }
			out.close();
		}
	 
		
		
		
		
	}