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

import java.util.*;

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

        int t = in.nextInt();
        long mod = 1_000_000_007L;
        for (int i=0;i<t;i++) {
            int x = in.nextInt();
            String s = in.next();
            StringBuilder sb = new StringBuilder(s);
            int index = 0;
            while (sb.length()<x) {
                int num = (int)sb.charAt(index)-48;
                if (num>1) {
                    int nn = sb.length();
                    for (int j=index+1;j<nn;j++) {
                        sb.append(sb.charAt(j));
                    }
                    if (num>2) {
                        for (int j=index+1;j<nn;j++) {
                            sb.append(sb.charAt(j));
                        }
                    }
                }
                index++;
            }
            long ans = s.length();
            for (int j=0;j<x;j++) {
                ans = ((long)(j+1)+((long)(ans-(j+1))*((long)((int)sb.charAt(j)-48)))%mod)%mod;
            }
            out.println(ans);
        }

        out.close();
    }

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

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

    }
}
