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

public class c 
{
	public static void main(String[] args) { new c(); }
	FS in = new FS();
	PrintWriter out = new PrintWriter(System.out);
	
	int t;
	int l, x, idx;
	char[] s, big;
	long ans, mod = (long)1e9 + 7;
	
	c() {
		t = in.nextInt();
		while (t --> 0) {
			x = in.nextInt();
			s = in.next().toCharArray();
			// filling big will only take O(x)
			// and sum x <= 10^6

			l = 0;
			idx = s.length;
			ans = s.length;
			big = new char[max(x, idx)];
			for (int i = 0; i < ans; i++)
				big[i] = s[i];
			while (l < x) {
				int to = (int)min(idx + (big[l] - '1') * (ans - (l + 1)), x);
				for (int i = 0; i < (big[l] - '1'); i++)
					for (int j = l + 1; idx < to && j < ans; j++)
						big[idx++] = big[j];
				ans = (l + 1) + (big[l] - '0') * (ans - (l + 1));
				ans = ((ans % mod) + mod) % mod;
				l++;
			}
			out.println(ans);
		}
		out.close();
	}
	
	

	int min(int a, int b) { if (a < b) return a; return b; }	
	int max(int a, int b) { if (a > b) return a; return b; }	
	long min(long a, long b) { if (a < b) return a; return b; }	
	long max(long a, long b) { if (a > b) return a; return b; }	

	boolean z(int x) { if (x == 0) return true; return false; }
	boolean z(long x) { if (x == 0) return true; return false; }
	
	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }
	}
}
