import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Random;

public class CutAndPaste implements Runnable {
   private static final int MOD = 1_000_000_007;
   public static void main(String[] args) {
      new CutAndPaste().run();
   }

   public void run() {
      try {
         runSolution();
      } catch (IOException ioe) {
      }
   }

   Random random = new Random();

   private void runSolution() throws IOException {
      InputStream inputStream = System.in;
      //InputStream inputStream = new FileInputStream(new File("CutAndPaste"));
      BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
      PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));

      CutAndPaste azamonWebServices = new CutAndPaste();

      long start = System.currentTimeMillis();
      String[] tokens;
      tokens = bufferedReader.readLine().split(" ");
      int T = Integer.valueOf(tokens[0]);
      for (; T > 0; T--) {
         tokens = bufferedReader.readLine().split(" ");
         int x = Integer.valueOf(tokens[0]);
         String s = bufferedReader.readLine();
         writer.println(azamonWebServices.length(s, x));
      }
      long end = System.currentTimeMillis();
      double time = 1d * (end - start) / 1000;
      //System.err.println(String.format("%f sec", time));

      writer.close();
      inputStream.close();

      //generateTestCases();
   }

   public int length(String s0, int x) {
      long size = s0.length();

      int[] s = new int[x+1];
      int n = 0;
      for (int i = 0; i < size && n < x; i++) {
         s[++n] = s0.charAt(i) - '0';
      }

      for (int l = 1; l <= x; l++) {
         if (n < x) {
            for (int copy = 2; copy <= s[l]; copy++) {
               for (int i = l+1; i <= size && n < x; i++) {
                  s[++n] = s[i];
               }
            }
         }
         size = (l + s[l] * (size - l)) % MOD;
      }

      size = (size + MOD) % MOD;

      return (int) size;
   }

   private void generateTestCases() {
      int maxX = 1000_000;
      int maxSize0 = 500;

      while (true) {
         String S0 = generateString(maxSize0);
         int x = 1+random.nextInt(maxX);
         if (length(S0, x) < 0) {
            System.err.println(String.format("%d %s", x, S0));
            break;
         }
      }
   }

   private String generateString(int n) {
      char[] c = new char[n];
      for (int i = 0; i < n; i++) {
         c[i] = (char) ('1' + random.nextInt(3));
      }
      return new String(c);
   }
}
