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.util.ArrayDeque;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        long MOD = (int) (1e9 + 7);

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int T = in.nextInt();
            for (int iter = 0; iter < T; iter++) {
                int x = in.nextInt();
                ArrayList<Integer> str = new ArrayList<>();
                char[] c = in.next().toCharArray();
                ArrayDeque<Integer> arr = new ArrayDeque<>();
                for (int i = 0; i < c.length; i++) {
                    str.add(Character.getNumericValue(c[i]));
                    arr.add(str.get(i));
                }
                long res = str.size();
                int l = 0;
                while (str.size() < x) {
                    l++;
                    arr.remove();
                    ArrayDeque<Integer> next = arr.clone();
                    res += (res - l) * (str.get(l - 1) - 1);
                    res %= MOD;
                    for (int it = 1; it < str.get(l - 1) && str.size() < x; it++) {
                        for (int j : next) {
                            str.add(j);
                            if (str.size() == x) {
                                break;
                            }
                        }
                        if (str.size() == x) {
                            break;
                        }
                        for (int j : next) {
                            arr.add(j);
                        }
                    }
                }
                for (int i = l + 1; i <= x; i++) {
                    res += (res - i) * (str.get(i - 1) - 1);
                    res %= MOD;
                }
                out.println(res);
            }
        }

    }

    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());
        }

    }
}

