#include <bits/stdc++.h>
using namespace std;
void file(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
template <typename Tp>
void read(Tp &x) {
  long long fh = 1;
  char c = getchar();
  x = 0;
  while (c > '9' || c < '0') {
    if (c == '-') {
      fh = -1;
    }
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c & 15);
    c = getchar();
  }
  x *= fh;
}
struct Edge {
  long long f, t, w, nxt;
} edge[2000005];
long long head[1000005], etot = 1;
void add_edge(long long f, long long t, long long w = 0) {
  edge[++etot] = (Edge){f, t, w, head[f]};
  head[f] = etot;
}
long long n, m;
char s[1000005];
long long len;
signed main() {
  long long T, fl = 0;
  read(T);
  while (T--) {
    read(m);
    scanf("\n%s", s + 1);
    n = strlen(s + 1);
    len = n;
    fl = 0;
    for (long long p = 1; p <= m; p++) {
      long long tmplen = len - p, newlen = len + (s[p] - '0' - 1) * tmplen;
      if (tmplen <= m && !fl) {
        for (long long j = 1; j < s[p] - '0'; j++) {
          for (long long k = 1; k <= tmplen; k++) {
            if (len + (j - 1) * tmplen + k > m) break;
            s[len + (j - 1) * tmplen + k] = s[p + k];
          }
        }
      }
      len = newlen % 1000000007;
      if (len != newlen) fl = 1;
      len = (len + 1000000007) % 1000000007;
    }
    printf("%lld\n", (len + 1000000007) % 1000000007);
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}
