#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void rd(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 - '0' + c, c = getchar();
  x *= f;
}
const int N = 1e6 + 10, mod = 1e9 + 7;
char str[N];
int s[N], len;
int n, m;
void Append(int l, int t) {
  int r = len;
  while (t--) {
    if (len == m) return;
    for (int i = l; i <= r && len < m; ++i) s[++len] = s[i];
  }
}
int main() {
  int T;
  rd(T);
  while (T--) {
    rd(m);
    scanf("%s", str + 1);
    n = strlen(str + 1);
    for (int i = 1; i <= n; ++i) s[i] = str[i] - '1' + 1;
    long long tot = len = n;
    for (int i = 1; i <= m; ++i) {
      Append(i + 1, s[i] - 1);
      tot = (tot + (tot - i + mod) * (s[i] - 1)) % mod;
    }
    printf("%lld\n", (tot + mod) % mod);
  }
  return 0;
}
