#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int, int>;
using ppi = pair<int, pii>;
using pll = pair<ll, ll>;
using pff = pair<lf, lf>;
using ti = tuple<int, int, int>;
using base = complex<double>;
const lf PI = 3.14159265358979323846264338L;
template <typename T>
inline T umax(T& u, T v) {
  return u = max(u, v);
}
template <typename T>
inline T umin(T& u, T v) {
  return u = min(u, v);
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int t;
  for (cin >> t; t--;) {
    int n;
    string S;
    cin >> n >> S;
    ll len = ((int)(S).size());
    bool flag = false;
    for (int i = 1; i <= n; i++) {
      int k = (len + mod - i) * (S[i - 1] - '1') % mod;
      if (!flag && len < n && S[i - 1] > '1') {
        string T = S.substr(i);
        for (int b = 0; b < S[i - 1] - '1'; b++) S += T;
        if (S.size() >= n + 5) S.resize(n + 5);
      }
      len += k;
      if (len >= n + 5) flag = true;
      len %= mod;
    }
    cout << len % mod << '\n';
    S.clear();
    S.shrink_to_fit();
  }
}
