import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int T = scan.nextInt();
        for (int o=0;o<T;o++){
            int x = scan.nextInt();
            StringBuilder str = new StringBuilder(scan.next());
            long sum = str.length();
            for (int i=1;i<=x;i++){
                if (str.length()<x){
                    String st = str.substring(i);
                    for (int j=0;j<str.charAt(i-1)-49;j++){
                        str.append(st);
                    }
                    sum = (str.length())%1000000007;
                }
                else{
                    sum = (sum+((sum-i)*(str.charAt(i-1)-49)))%1000000007;
                }
            }
            System.out.println(sum);
        }
    }
}