import java.util.*; 
public class JavaApplication14 {
    
    public static void main(String[] args) {
        Scanner io = new Scanner(System.in);
        int t = io.nextInt();
        while(t-- != 0) {
            int x = io.nextInt();
            String str = io.next();
            long res = 0;
            long[] lengthSoFar = new long[x+1];
            lengthSoFar[0] = str.length();
            for(int i = 1; i <= x; i++) {
                int a = (int)(str.charAt(i-1)-'0');
                // 7 23233232332323323
                lengthSoFar[i] = (i + (lengthSoFar[i-1] - i)*a);
                if(str.length() < x) {
                    String z = str.substring(i);
                    for(int j = 1; j < a; j++)
                        str += z;
                }
            }
            System.out.println(lengthSoFar[x] % (1000000000+7));
        }
    }
}