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

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    public static void main(String[] args) throws IOException {
        Main main = new Main();
        int t = sc.nextInt();
        while(t-->0){
            main.solve();
        }
        out.flush();
    }
    void solve(){
        int x = sc.nextInt();
        String s = sc.next();
        ArrayList<Character> list = new ArrayList<>(s.length());
        for(char c:s.toCharArray()) list.add(c);
        int idx = 0;
        long ans = s.length(), mod = 1000000000+7;
        boolean flag = false;
        while(idx<x){
            idx++;
            long curLen = ans;
            int num = list.get(idx-1)-'0';
            for(int time=1; time<num;time++){
                flag |= list.size()>x;
                if(flag) break;
                for(int i=idx; i<curLen; i++) list.add(list.get(i));
            }
            ans += (num-1)*((ans+mod-idx)%mod);
            ans %= mod;
        }
        out.println(ans);
    }
}

