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();
            char[] chr = io.next().toCharArray();
            long[] lengthSoFar = new long[x+1];
            lengthSoFar[0] = chr.length;
            ArrayList<Integer> arr = new ArrayList<>();
            for(int i = 0; i < chr.length; i++) arr.add((int)(chr[i]-'0'));
            for(int i = 1; arr.size() < x && i <= x; i++) {
                int a = arr.get(i-1);
                if(a == 1) continue;
                int m = arr.size();
                while(arr.size() < x && a-- != 1)
                    for(int j = i; arr.size() < x && j < m; j++) arr.add(arr.get(j));
            }
            
            for(int i = 1; i <= x; i++) {
                int a = arr.get(i-1);
                lengthSoFar[i] = (i + ((((lengthSoFar[i-1]) - i)*a) % (1000000000+7)));
            }
            System.out.println(lengthSoFar[x] % (1000000000+7));
        }
    }
}