import java.math.BigInteger;
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];
            //BigInteger[] lenSoFar = new BigInteger[1+x];
            lengthSoFar[0] = str.length();
            //lenSoFar[0] = BigInteger.valueOf(str.length());
            if(str.length() < x) {
                for(int i = 1; str.length() < x && i <= x; i++) {
                    int a = (int)(str.charAt(i-1)-'0');
                    if(str.length() < x) {
                        String z = str.substring(i);
                        for(int j = 1; str.length() < x && j < a; j++)
                            str += z;
                    }
                }
            }
            for(int i = 1; i <= x; i++) {
                int a = (int)(str.charAt(i-1)-'0');
                lengthSoFar[i] = (i + ((((lengthSoFar[i-1] % (1000000000+7)) - i)*a) % (1000000000+7)));
                //lenSoFar[i] = BigInteger.valueOf(i).add(lenSoFar[i-1].subtract(BigInteger.valueOf(i)).multiply(BigInteger.valueOf(a))).mod(BigInteger.valueOf(1000000000+7));
            }
            System.out.println(lengthSoFar[x] % (1000000000+7));
            //System.out.println(lenSoFar[x].mod(BigInteger.valueOf(1000000000+7)));
        }
    }
}