import java.util.*;

public class Main {

    public static long MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        for (int i = 0; i < t; i++) {
            long x = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();
            ArrayList<Character> charsList = new ArrayList<>();
            long ans = s.length();
            for (int j = 0; j < s.length(); j++) {
                charsList.add(s.charAt(j));
            }
            for (int j = 0; j < x; j++) {
                long copiesCount = charsList.get(j) - '0' - 1;
                long startIndex = j + 1;
                long endIndex = charsList.size();
                if(ans <= startIndex) {
                    ans+=MOD;
                }
                ans += (copiesCount * (ans - startIndex));
                ans %= MOD;
                if (charsList.size() <= x) {
                    for (int k = 0; k < copiesCount; k++) {
                        for (long f = startIndex; f < endIndex; f++) {
                            charsList.add(charsList.get((int) f));
                        }
                    }
                }

            }
            System.out.println(ans);
        }

    }


}
