import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Code {
    public static void main(String[] args)throws IOException {

        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int t = sc.nextInt();
        while(t-->0) {
            long n = sc.nextLong();
            String s = sc.next();
            char[] a = new char[(int)n];
            Arrays.fill(a,'/');
            long mod = 1000000007;
            long len = s.length();
            long x = len;
            for(int i=0;i<Math.min(x,n);i++) {
                a[i]=s.charAt(i);
            }
            for(long i=0;i<n;i++) {
                long val = Long.parseLong(String.valueOf(a[(int)i]));
                len = (i+1+(val*(len-i-1))%mod+mod)%mod;
                if(x<n) {
                    long count=0;
                    for(long j=x;j<len;j++) {
                        if(a[(int)n-1]=='/') {
                            a[(int)j]=a[(int)(i+1+count)];
                            count++;
                        }
                    }
                    x=x+count;
                }

            }
            out.println(len);
            out.flush();
        }
        //out.print("5");
        out.close();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}

