#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecVec = vector<Vec>;
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const ll INF = 1e9 + 1;
const ll LINF = 1e18 + 1;
const ll MOD = 1e9 + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
void solve() {
  ll x;
  cin >> x;
  string a;
  cin >> a;
  ll re = 0, len = a.length();
  bool flg = false;
  for (ll(i) = (0); (i) < (x); ++(i)) {
    re = a[i] - '0';
    if (!flg) {
      string subA = a.substr(i + 1, len - i - 1);
      for (ll(i) = (0); (i) < (re - 1); ++(i)) {
        a += subA;
      }
    }
    ll tmp = len - i - 1;
    if (tmp < 0) tmp += MOD;
    len += (re - 1) * tmp;
    if (len >= x) flg = true;
    if (flg) len %= MOD;
  }
  cout << (len) << endl;
}
int main(void) {
  ll t;
  cin >> t;
  for (ll(i) = (0); (i) < (t); ++(i)) solve();
  return 0;
}
