#include <bits/stdc++.h>
using namespace std;
inline long long Getint() {
  char ch = getchar();
  long long x = 0, fh = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') fh = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    (x *= 10) += ch ^ 48;
    ch = getchar();
  }
  return x * fh;
}
const long long mod = 1000000007;
const int inf = 1 << 25;
const int N = 2000005;
char s[N];
int n, x;
long long len, l;
inline void Pas(int l, int r, int t) {
  len += t * (len - l + 1) % mod;
  len %= mod;
  for (int i = 1; i <= t; i++) {
    for (int j = l; j <= r; j++) {
      if (n > x) break;
      s[++n] = s[j];
    }
  }
}
int main() {
  int T = Getint();
  while (T--) {
    x = Getint();
    scanf("%s", s + 1);
    n = strlen(s + 1);
    l = 0;
    len = n;
    for (int i = 1; i <= x; i++) {
      l++;
      int t = s[l] - '0';
      Pas(l + 1, n, t - 1);
    }
    cout << len << '\n';
  }
  return 0;
}
