import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader scan = new Reader();
        scan.init(System.in);
        OutputStream output = System.out;
        PrintWriter out = new PrintWriter(output);
        int T = scan.nextInt();
        for (int o=0;o<T;o++){
            int x = scan.nextInt();
            StringBuilder str = new StringBuilder(scan.next());
            long sum = str.length();
            int flag = 0;
            for (int i=1;i<=x;i++){
                if (flag==0){
                    if (str.charAt(i-1)=='2'){
                        String st = str.substring(i);
                        str.append(st);
                    }
                    else if (str.charAt(i-1)=='3'){
                        String st = str.substring(i);
                        str.append(st);
                        str.append(st);
                    }
                    sum = (sum+((sum-i)*(str.charAt(i-1)-49)))%1000000007;
                    if (str.length()>=x){
                        flag=1;
                    }
                }
                else if (flag==1){
                    sum = (sum+((sum-i)*(str.charAt(i-1)-49)))%1000000007;
                }
            }
            out.println((sum+1000000007)%1000000007);
        }
        out.close();
    }
}
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}