// package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class BD3 {
    public static void main(String[] Args){
        FastReader scan=new FastReader();
        StringBuilder print=new StringBuilder();
        int t=scan.nextInt();
        while(t-->0){
            int x=scan.nextInt();
            String s=scan.next();
            StringBuilder os=new StringBuilder(s);
            int i=0;
            while(os.length()<x){
                int oc=os.charAt(i)-'0';
                int l=os.length();
                for(int j=1;j<oc&&os.length()<x;j++){
                    for(int k=i+1;k<l&&os.length()<x;k++){
                        os.append(os.charAt(k));
                    }
                }
                i++;
            }
            long mod=1000000007;
            int l=0;
            long rl=s.length()-1;
            long tl=0;
            for(i=1;i<=x;i++){
                l++;
                int oc=os.charAt(i-1)-'0';
                long al=(rl*oc)%mod;
                tl=(l+al)%mod;
                rl=(al-1+mod)%mod;
            }
            print.append(tl+"\n");
        }
        System.out.println(print);
    }
    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;
        }
    }

}
