import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	PrintWriter out = new PrintWriter(System.out);
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok = new StringTokenizer("");
    String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    }
    int ni() throws IOException { return Integer.parseInt(next()); }
    long nl() throws IOException { return Long.parseLong(next()); }
  
    void solve() throws IOException {
        for (int TC=ni();TC>0;TC--) {
            long m=1000000007;
            int x=ni();
            String s=next();
            int[]A=new int[1000100];
            for (int z=0;z<s.length();z++) A[z+1]=(int)(s.charAt(z)-'0');
            
            long n=s.length();
            int p=0;
            int q=(int)n+1;
            
            while (q<=x) {
                p++;
                int c=A[p]-1;
                
                outer:
                for (int z=0;z<c;z++) {
                    for (int y=p+1;y<=n;y++) {
                        A[q]=A[y];
                        q++;
                        if (q>x) break outer;
                    }
                }
                n=n+(c*(n-p));
            }
            
            while (p<x) {
                p++;
                long r=(n+m-p)%m;
                n=(n+r*(A[p]-1))%m;
            }
            out.println(n);
        }
        out.flush();
    }
    
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }
}