#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
void solve() {
  ll x;
  string s;
  cin >> x >> s;
  ll res = s.size();
  for (int i(0); i < x; ++i) {
    ll add = (res - i - 1 + mod) % mod;
    for (int j(0); j < s[i] - '1'; ++j) {
      if (s.size() < x) {
        s += s.substr(i + 1, min<ll>(x - res, add));
      }
      res = (res + add) % mod;
    }
  }
  cout << res << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
