#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-7;
const long long int m = 1000000007;
void solve() {
  int x;
  string s;
  cin >> x >> s;
  long long int ans = s.length();
  string trk = s;
  for (int i = 1; i <= x; i++) {
    int q;
    q = trk[i - 1] - '1';
    if (trk.length() < x) {
      int len = trk.length();
      string sub = trk.substr(i, len - i + 1);
      for (int j = 0; j < q; j++) {
        trk += sub;
      }
    }
    ans = (ans + (ans - i) * q) % m;
  }
  cout << (ans % m + m) % m << '\n';
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
