/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
    static int n,k;
    static String s;
    static int MOD = (int)1e9+7;
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner input = new Scanner(System.in);
		int test = input.nextInt();
		while(test-->0){
		     k = input.nextInt();
		     input.nextLine();
		     s = input.nextLine();
		     n = s.length();
		    ArrayList<Character>list = new ArrayList<>();
		    long size =n;
		    for(int i =0;i<n;i++)list.add(s.charAt(i));
		    for(int i =1;i<=k;i++){
		        int times = list.get(i-1)-'0';
		        times--;
		        if(list.size()<k){
		            int ss = list.size();
		            for(int j =0;j<times;j++){
		                copy(i,list,ss);
		            }
		        }
		        size = ((size+((size-i)*times)%MOD)%MOD+MOD)%MOD;
		        
		    }
		    System.out.println(size);
		    
		}
	}
	public static void copy(int index,ArrayList<Character>list,int ss){
	    for(int i =index;i<ss;i++){
	        list.add(list.get(i));
	    }
	}
}
