import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.StringTokenizer;

public class C {

	public static void main(String[] args) throws Exception {
//		StringTokenizer stok = new StringTokenizer(new Scanner(new File("F:/books/input.txt")).useDelimiter("\\A").next());
		StringTokenizer stok = new StringTokenizer(new Scanner(System.in).useDelimiter("\\A").next());
		StringBuilder sb = new StringBuilder();
		Integer T = Integer.parseInt(stok.nextToken());
		long mod = (long) 1e9+7;
		while(T-->0) {
			Integer x  = Integer.parseInt(stok.nextToken());
			String s = stok.nextToken();
			int[] a = new int[Math.max(x+1,s.length())];
			for(int i=0;i<s.length();i++) a[i] = s.charAt(i)-49;
			long m = s.length();
			int l=0;
			boolean cx = false;
			while(l<x) {
				l++;
				long v = a[l-1];
				long v2 = m-l;
				long prevm = m;
				m = (m+(m-l)*v)%mod;
				if(v>0)
				if(!cx) {
					for(int i=(int) prevm;i<prevm+v2;i++) {
						if(i<=x) {
							a[i] = a[(int) (i-v2)];
						}
						if(v==2) {
							if((i+v2)<=x) {
								a[(int) (i+v2)] = a[(int) (i-v2)];
							}
						}
					}
				}
				if(m>=x) cx=true;
			}
			System.out.println(m);
		}
	}

}
