import java.util.Scanner;

public class que3 {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int test = scn.nextInt();

		for (int t = 1; t <= test; t++) {
			int x = scn.nextInt();
			String s = scn.next();
			StringBuilder sb = new StringBuilder(s);

			long ans = sb.length();
			int mod = 1000000007;
			boolean f = false;
			long last = sb.length();
			for (int i = 0; i < x; i++) {
				int val = sb.charAt(i) - '0';
				int l = i + 1;
				if (l > sb.length()) {
					System.out.println(2);
					continue;
				}
				if (val == 2) {

					long tl = (last + (last - l + mod) % mod) % mod;
					ans = tl;
					last=tl;
					if (sb.length() < x) {
						sb.append(sb.substring(l));

					}
				} else if (val == 3) {

					long tl = (last + (2 * ((last - l + mod) % mod) % mod)) % mod;
					ans = tl;
					last = tl;

					if (sb.length() < x) {
						String ls = sb.substring(l);
						sb.append(ls);
						sb.append(ls);
					}

				}
			}

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