#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
using namespace std;
namespace _c {
const double pi = acos(-1.0);
namespace min {
const int i8 = -128;
const int i16 = -32768;
const int i = -2147483647 - 1;
const long long l = -9223372036854775807LL - 1;
}  // namespace min
namespace max {
const int i8 = 127;
const int i16 = 32767;
const int i = 2147483647;
const long long l = 9223372036854775807LL;
}  // namespace max
}  // namespace _c
namespace _f {
template <typename T>
inline const T gcd(T m, T n) {
  while (n != 0) {
    T t = m % n;
    m = n;
    n = t;
  }
  return m;
}
template <typename T>
inline const T abs(const T &a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline T pow(T a, T b) {
  T res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a;
    }
    a = a * a;
    b >>= 1;
  }
  return res;
}
template <typename T>
inline T pow(T a, T b, const T &m) {
  a %= m;
  T res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a % m;
    }
    a = a * a % m;
    b >>= 1;
  }
  return res % m;
}
}  // namespace _f
namespace io {
template <typename T>
inline T read() {
  register T res = 0, neg = 1;
  char g = getchar();
  for (; !isdigit(g); g = getchar()) {
    if (g == '-') {
      neg = -1;
    }
  }
  for (; isdigit(g); g = getchar()) {
    res = res * 10 + g - '0';
  }
  return res * neg;
}
template <typename T>
inline void read(T &t) {
  t = read<T>();
}
template <typename T>
inline void readln(const T first, const T last) {
  for (register T it = first; it != last; it++) {
    read(*it);
  }
}
template <typename T>
inline void _write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) {
    _write(x / 10);
  }
  putchar(x % 10 + '0');
}
template <typename T>
inline void write(const T &x, const char &sep = ' ') {
  _write(x);
  putchar(sep);
}
template <typename T>
inline void writeln(const T &x) {
  write(x, '\n');
}
template <typename T>
inline void writeln(const T first, const T last, const char &sep = ' ',
                    const char &ends = '\n') {
  for (register T it = first; it != last; it++) {
    write(*it, sep);
  }
  putchar(ends);
}
}  // namespace io
int T;
int x;
string s;
const int MOD = 1e9 + 7;
const int N = 1e6 + 5;
int a[N];
inline void add(int &x, int y) { (x += y) %= MOD; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> T;
  while (T--) {
    cin >> x;
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
      a[i + 1] = s[i] - '1';
    }
    int len = s.length();
    int cnt = len;
    for (int i = 1; i <= x && i <= cnt; i++) {
      if (cnt < x) {
        for (int j = 1; j <= a[i]; j++) {
          for (int k = i + 1; k <= len; k++) {
            a[++cnt] = a[k];
            if (cnt == x) {
              break;
            }
          }
          if (cnt == x) {
            break;
          }
        }
      }
      int t = len - i;
      if (t < 0) {
        add(t, MOD);
      }
      add(len, t * a[i] % MOD);
      if (len < 0) {
        add(len, MOD);
      }
    }
    cout << len << "\n";
  }
}
