import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long x = in.nextInt();
            StringBuilder s = new StringBuilder(in.next());
            long c = s.length();
            long mod = 1_000_000_007L;
            for (int i = 0; i < x; i++) {
                for (int j = 0; j < s.charAt(i) - '0' - 1; j++) {
                    if (s.length() > x) {
                        break;
                    }
                    s.append(s.substring(i + 1));
                }
                long xx = (c - i - 1 + mod);
                xx %= mod;
                xx *= ((s.charAt(i) - '0' - 1));
                xx %= mod;
                c = c + xx;
                c %= mod;
//            out.println(c);
//            c = (c - 1 + mod)%mod;
//            c =  c*(s.charAt(i)-'0');
//            c%=mod;
//            out.println(s.toString() + " " + (c+ i + 1));
            }
            out.println(c);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

