#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long llinf = (1LL << 62);
const int inf = (1 << 30);
const int nmax = 5e6 + 50;
const long long mod = 1e9 + 7;
using namespace std;
int t, i, nr, j, x, bl, n;
string s;
char c[nmax];
long long cur, cur1;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> x >> s;
    n = (int)s.size();
    for (i = 1; i <= n; i++) c[i] = s[i - 1];
    cur = n, bl = 0;
    if (cur >= x) bl = 1;
    for (i = 1; i <= x; i++) {
      if (!bl) {
        cur1 = cur;
        for (nr = 1; nr <= (c[i] - '0') - 1; nr++) {
          for (j = i + 1; j <= cur1; j++) c[++cur] = c[j];
        }
        if (cur >= x) bl = 1;
      } else {
        cur += ((cur - i + mod) % mod * 1LL * (c[i] - '0' - 1) % mod);
        cur %= mod;
      }
    }
    cout << cur << '\n';
  }
  return 0;
}
