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

public class P607C {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        for(int i=0; i<t; i++) {
            int x = Integer.parseInt(br.readLine());
            String s = br.readLine();
            ArrayList<Integer> vals = new ArrayList<>();
            for(int j=0; j<s.length() && j<x; j++) {
                vals.add(Integer.parseInt("" + s.charAt(j)));
            }
            long curLength = s.length();

            long mod = 1000000007;

            for(int j=0; j<x; j++) {
                int reps = vals.get(j);
                curLength += ((curLength - j - 1) * (reps - 1));
                curLength = (curLength + mod) % mod;
                int curEnd = vals.size();
                for(int k=1; k<reps; k++) {
                    int curPos = j+1;
                    while(vals.size() < x && curPos < curEnd) {
                        vals.add(vals.get(curPos));
                        curPos++;
                    }
                }
            }

            System.out.println(curLength);

        }

    }
}
