/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
*/
import java.util.*;
import java.io.*;

   public class C
   {
      public static void main(String args[]) throws Exception
      {
         //BufferedReader infile = new BufferedReader(new FileReader("cowdate.in"));
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int T = Integer.parseInt(st.nextToken());
         StringBuilder sb = new StringBuilder();
         for(int qwe=0; qwe < T; qwe++)
         {
            int X = Integer.parseInt(infile.readLine());
            String input = infile.readLine();
            int N = input.length();
            int[] arr = new int[N];
            for(int i=0; i < N; i++)
               arr[i] = Integer.parseInt(input.charAt(i)+"");
            //only need to store first X numbers
            ArrayList<Integer> needed = new ArrayList<Integer>();
            for(int q: arr)
               needed.add(q);
            long res = N;
            long MOD = 1000000007L;  
            for(int a=0; a < X; a++)
            {
               int s = needed.get(a);
               int size = needed.size();
               res += ((res-a-1)*(s-1)%MOD);
               res %= MOD;
               outer:for(int qw=0; qw < s-1; qw++)
                  for(int i=a+1; i < size; i++)
                  {
                     if(needed.size() > X+2)
                        break outer;
                     needed.add(needed.get(i));
                  }
               //end
            }
            sb.append(res+"\n");
         }
         System.out.print(sb.toString());
      }
   }