import java.io.*;
import java.util.*;
 
public class utkarsh {
    
    BufferedReader br;
    PrintWriter out;
    
    long mod = (long) (1e9 + 7), inf = (long) (3e18);
    
    class pair {
        int L, R;
        pair(int l, int r) {
            L = l;  R = r;
        }
    }
    
    void solve() {
        int t = ni();
        while(t-- > 0) {
            int n = ni();
            String s = ns();
            long ans = -1;
            for(int i = 0; i < n; i++) {
                if(s.length() < n) {
                    int x = s.charAt(i) - '0';
                    String g = s.substring(i+1);
                    s = s.substring(0, i+1);
                    while(x-- > 0) {
                        s = s + g;
                    }
                } else {
                    if(ans == -1)   ans = s.length();
                    int x = s.charAt(i) - '0';
                    ans = (ans + (ans - i - 1) * (x-1)) % mod;
                }
            }
            out.println(ans == -1 ? s.length() : ans);
        }
    }
    
    long mp(long b, long e) {
        long r = 1;
        while(e > 0) {
            if( (e&1) == 1 )    r = (r * b) % mod;
            b = (b * b) % mod;
            e >>= 1;
        }
        return r;
    }
    
    // -------- I/O Template -------------
    
    char nc() {
        return ns().charAt(0);
    }
    
    String nLine() {
        try {
            return br.readLine();
        } catch(IOException e) {
            return "-1";
        }
    }
    
    double nd() {
        return Double.parseDouble(ns());
    }
    
    long nl() {
        return Long.parseLong(ns());
    }
    
    int ni() {
        return Integer.parseInt(ns());
    }
    
    StringTokenizer ip;
    
    String ns() {
        if(ip == null || !ip.hasMoreTokens()) {
            try {
                ip = new StringTokenizer(br.readLine());
            } catch(IOException e) {
                throw new InputMismatchException();
            }
        }
        return ip.nextToken();
    }
    
    void run() {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }
    
    public static void main(String[] args) {
        new utkarsh().run();
    }
}
