#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long x;
    cin >> x;
    string s;
    cin >> s;
    long long maxi = 1000002;
    long long mod = 1e9 + 7;
    long long ans = s.length();
    long long l = 0;
    while (l < x) {
      l++;
      string temp = "";
      long long len = s.length();
      long long cut = ans - l;
      cut = (cut + mod) % mod;
      cut = (cut + mod) % mod;
      ans = l;
      for (long long i = l; i <= min(len - 1, maxi); i++) {
        temp.push_back(s[i]);
      }
      for (long long j = 1; j <= (s[l - 1] - '0'); j++) {
        ans += cut;
        if (s.length() < maxi) s += temp;
        ans = (ans + mod) % mod;
        ans = (ans + mod) % mod;
      }
    }
    ans = (ans + mod) % mod;
    ans = (ans + mod) % mod;
    cout << ans << endl;
  }
  return 0;
}
