#include <bits/stdc++.h>
using namespace std;
int const N = 1e6 + 10;
int oo = 1e9;
int mod = oo + 7;
long long OO = 3e18;
int x;
string s;
void solve() {
  cin >> x;
  cin >> s;
  int l = 0;
  long long lon = s.size();
  while (l != x) {
    l++;
    int cnt = s[l - 1] - '0' - 1, h = l, unt = lon;
    lon += cnt * 1LL * (lon - l + mod) % mod;
    lon %= mod;
    while (cnt && (int)s.size() <= x && h < (int)s.size()) {
      s += s[h];
      h++;
      if (h == unt) {
        h = l;
        cnt--;
      }
    }
  }
  cout << lon << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
