import org.omg.PortableServer.POA;

import java.awt.*;
import java.io.*;
import java.util.*;

public class Abc {
    public static void main(String[] args) throws IOException {
        FastReader sc = new FastReader();
        int t=sc.nextInt();
        int mod=(int) 1e9+7;
        while (t-->0){
            int x=sc.nextInt();
            String s=sc.next();
            StringBuilder sb=new StringBuilder(s);
            int c=1;
            while (sb.length()<x){
                if (sb.charAt(c-1)=='2'){
                    sb.append(sb.substring(c));
                }
                if (sb.charAt(c-1)=='3'){
                    sb.append(sb.substring(c));
                    sb.append(sb.substring(c));
                }
                c++;
            }
            String a=sb.toString();
            long curr=s.length();
            for (int i=0;i<x;i++){
                curr=((curr-(i+1))*(a.charAt(i)-'0')+(i+1))%mod;
            }
            System.out.println(curr);

        }
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}