// Main Code at the Bottom
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger; 
public class Main {
	//Fast IO class
    static class FastReader {
        BufferedReader br; 
        StringTokenizer st; 
        public FastReader() {
        	boolean env=System.getProperty("ONLINE_JUDGE") != null;
        	if(!env) {
        		try {
					br=new BufferedReader(new FileReader("src\\input.txt"));
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				}
        	}
        	else 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; 
        } 
    }     
    static long MOD=1000000000+7;
    //debug
    static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    // Pair
    static class pair{
    	long x,y;
    	pair(long a,long b){
    		this.x=a;
    		this.y=b;
    	}
    	public boolean equals(Object obj) {
    		if(obj == null || obj.getClass()!= this.getClass()) return false;
            pair p = (pair) obj;
            return (this.x==p.x && this.y==p.y);
        }
    	public int hashCode() {
            return Objects.hash(x,y);
        }
    }
    static FastReader sc=new FastReader();
    static PrintWriter out=new PrintWriter(System.out);  
    //Main function(The main code starts from here)
    public static void main (String[] args) throws java.lang.Exception {
    	int test=1;
    	test=sc.nextInt();
    	while(test-->0){
    		int x=sc.nextInt();
    		char s[]=sc.nextLine().toCharArray();
    		ArrayList<Integer> tmp=new ArrayList<>();
    		for(char c: s) tmp.add(c-'0');
    		int cur=0;
    		long R=s.length-1;
    		while(tmp.size()<x) {
    			if(cur==x) break;
    			int val=tmp.get(cur++)-1;
    			int l=cur,r=(int)R;
    			for(int i=0;i<val;i++) {
    				if(tmp.size()>=x) break;
    				for(int j=l;j<=r;j++) {
    					tmp.add(tmp.get(j));
    					if(tmp.size()>=x) break;
    				}
    			}
    			long len=((R%MOD-cur%MOD+MOD)%MOD+1%MOD)%MOD;
    			R=(R%MOD+(val*(len))%MOD)%MOD;
    		}
    		while(cur!=x) {
    			long val=tmp.get(cur++)-1;
    			long len=((R%MOD-cur%MOD+MOD)%MOD+1%MOD)%MOD;
    			R=(R%MOD+(val*(len))%MOD)%MOD;
    		}
    		out.println((R%MOD+1)%MOD);
    	}
        out.flush();
        out.close();
    }
}