import java.io.*;
import java.util.*;
 
public class Main {
	static class FastReader{ 
        BufferedReader br; 
        StringTokenizer st; 
        public FastReader(){br = new BufferedReader(new InputStreamReader(System.in));}
        String next(){while (st == null || !st.hasMoreElements()){try{st = new StringTokenizer(br.readLine());} 
        catch (IOException  e){e.printStackTrace();}}return st.nextToken();}
        int nextInt(){ return Integer.parseInt(next());}long nextLong(){return Long.parseLong(next());}double nextDouble(){return Double.parseDouble(next());}
        String nextLine(){String str = ""; try{str = br.readLine(); } catch (IOException e) {e.printStackTrace();} return str; } 
    }
	static FastReader sc = new FastReader();
	static long mod = (long)(1e9+7);
	public static void main (String[] args){
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;
        t = sc.nextInt();
        z :while(t-->0){
        	int x = sc.nextInt();
        	String str = sc.next();
        	long n = str.length();
        	int idx = str.length();
        	long ans = str.length();
        	char []s = new char[Math.max(x, idx)];
        	for(int i=0;i<idx;i++)
        		s[i] = str.charAt(i);
        	int l = 0;
        	while(l<x) {
        		int add = (int) Math.min(idx+(s[l]-'1')*(ans-(l+1)), x);
        		for(int i=0;i<(s[l]-'1');i++) {
        			for(int j=l+1;j<ans&&idx<add;j++)
        				s[idx++] = s[j];
        		}
        		ans = (l+1) + (s[l]-'0')*(ans-(l+1));
        		ans = ((ans%mod)+mod)%mod;
        		l++;
        	}
        	out.write(ans+"\n");
       	}
		out.close();
	}
}
