#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& i : v) is >> i;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
  for (auto& i : v) os << i << ' ';
  return os;
}
const ll N = 1e5 + 5;
const ll mod = 1e9 + 7;
vector<ll> fact(ll n) {
  vector<ll> x;
  ll i;
  for (i = 1; i <= n; i++) {
    if (n % i == 0) x.push_back(i);
  }
  return x;
}
ll factorial(ll x) {
  ll i = 1;
  while (x) {
    i *= x;
    i = i % mod;
    x--;
  }
  return i;
}
ll power(ll x, ll y, ll p = mod) {
  ll res = 1;
  x %= p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
ll nCr(ll n, ll r, ll m = mod) {
  if (r > n) return 0;
  ll a = 1, b = 1;
  while (r) {
    a = (a * n) % m;
    --n;
    b = (b * r) % m;
    --r;
  }
  return (a * power(b, m - 2, m)) % m;
}
bool bysec(pair<ll, ll>& a, pair<ll, ll>& b) { return a.second < b.second; }
void solve() {
  ll x;
  cin >> x;
  string s;
  cin >> s;
  long long ans = 0;
  ans = s.size();
  for (int i = 0; i < x; i++) {
    ll z = (s[i] - '0');
    z--;
    ans += (z) * (ans - i - 1);
    ans %= mod;
    if (s.size() < x) {
      string tmp = s.substr(i + 1);
      while (z--) s += tmp;
    }
  }
  cout << ans;
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n = 1;
  cin >> n;
  while (n--) {
    solve();
  }
}
