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

/*
───────────────■■■─────────────────────────
──█▄─▄█─▄▀▀▀▄─█──▄█─────█──▄▀─▄▀▀▀▄─▀▀█▀▀──
──█─▀─█─█───█─█─█─█─────█■█───█───█───█────
──█───█─▀▄▄▄▀─█▀──█─────█──▀▄─▀▄▄▄▀───█────
───────────────────────────────────────────
*/

public class Main {

    static FastReader in;
    static PrintWriter out;
    static Random rand = new Random();
    static final int INF = (int) (1e9);
    static final int MOD = (int) (1e9 + 7);

    static void solve() {
        int x = in.nextInt();
        StringBuilder s = new StringBuilder(in.next());
        int n = s.length();

        int j = 0;
        while (j < s.length() && s.length() < x) {
            int cnt = s.charAt(j) - '1';
            int l = j + 1, r = s.length();
            while (cnt-- > 0 && s.length() < x) {
                for (int i = l; i < r && s.length() < x; i++) {
                    s.append(s.charAt(i));
                }
            }
            j++;
        }
        x = Math.min(x, s.length());

        long sum = 0, lol = 1;
        for (int i = x - 1; i >= 0; i--) {
            int cnt = s.charAt(i) - '0';
            lol = (lol * cnt) % MOD;
            sum = (sum + lol) % MOD;
        }

        lol = (lol * n) % MOD;
        lol = (lol - sum + MOD) % MOD;

        out.println((x + lol) % MOD);
    }

    public static void main(String[] args) {
        in = new FastReader(System.in);
//        in = new FastReader(new FileInputStream("input.txt"));
        out = new PrintWriter(System.out);
//        out = new PrintWriter(new FileOutputStream("output.txt"));


        int q = in.nextInt();

        while (q-- > 0) {
            solve();
        }

        out.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

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

        Long nextLong() {
            return Long.parseLong(next());
        }

        Double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }
}