// package tutorial.modulararithmetic;

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

public class CutAndPaste {
	private static final FastReader in = new FastReader();
	private static final PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		Solver sol = new Solver();
		int tt = 1;
		for (int qq = in.nextInt(); tt <= qq; ++tt)
			sol.solve(tt);
		out.close();
	}

	private static final class Solver {
		static final long MOD = 1000000007L;

		public void solve(int testCase) {
			int x = in.nextInt();
			StringBuilder a = new StringBuilder(in.next());
			long ans = a.length() % MOD;
			for (int len = 1; len <= x; ++len) {
				int l = a.charAt(len - 1) - '1';
				ans += (ans - len) * l;
				ans %= MOD;
				if (a.length() < x && l > 0) {
					String  select = a.substring(len, a.length());
					a.append(select.repeat(l));
				}
			}

			System.out.println(ans % MOD);
		}
	}

	private static final class FastReader {
		private BufferedReader br;
		private StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in), 1 << 16);
			st = null;
		}

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

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