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


 
public class Main{
	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 = (int) 1e5;
    public static int x = 0;
	public static void main(String[] args) {
		FastReader sc = new FastReader();
        
		 int t = sc.nextInt();
		    while(t-->0) {
		    	int x = sc.nextInt();
		    	long len = -1;
		    	String sb = sc.next();
		    	List<Character> list = new ArrayList<>();
		    	for(char c : sb.toCharArray()) list.add(c);
		    	
		    	for(int i=0;i<x;++i) {
		    		
		    		if(list.size() < x) {
		    		int till = list.size();
		    		
		    		for(int re=0;re+1<list.get(i)-'0';++re) {
		    		for(int j=i+1;j<till;++j) {
		    			list.add(list.get(j));
		    		}
		    		}
		    		//out.println(s+" "+sb);
		    		}else {
		    			if(len == -1) len = list.size()-i-1;
		    			else len = (len-1+mod)%mod;
		    			//out.println(len);
		    			long freq = list.get(i)-'0';
		    			len = (freq*len)%mod;
		    		}
		    	}
		    	out.println((len+x)%mod);
		    	
		    	
		    }
		    out.close();
}
	
}