// practice with kaiboy
import java.io.*;
import java.util.*;

public class CF1281C extends PrintWriter {
	CF1281C() { super(System.out); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1281C o = new CF1281C(); o.main(); o.flush();
	}

	static final int MD = 1000000007;
	void main() {
		int t = sc.nextInt();
		byte[] cc = new byte[1000000];
		while (t-- > 0) {
			int x = sc.nextInt();
			byte[] aa = sc.next().getBytes();
			int n = aa.length;
			boolean done = n >= x;
			for (int i = 0; i < n; i++)
				cc[i] = aa[i];
			for (int i = 1; i <= x; i++) {
				int k = cc[i - 1] - '1', m = n - i;
				int n_ = (int) ((n + (long) k * m) % MD);
				while (k-- > 0 && !done) {
					m = Math.min(m, x - n);
					for (int h = 0; h < m; h++)
						cc[n + h] = cc[i + h];
					n += m;
					if (n >= x)
						done = true;
				}
				n = n_;
			}
			if (n < 0)
				n += MD;
			println(n);
		}
	}
}
