#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double pii = 2 * pi;
const double eps = 1e-6;
const double inf = 1e15;
long long int remp[1000005], rems[1000005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int x;
    cin >> x;
    string s;
    cin >> s;
    long long int n = s.length();
    long long int ans = n;
    for (long long int i = 1; i <= x; i++) {
      if (x > s.length()) {
        long long int k = s[i - 1] - '1';
        long long int len = s.length();
        while (k--) {
          for (long long int j = i; j < len; j++) {
            s += s[j];
            if (s.length() >= x) break;
          }
          if (s.length() >= x) break;
        }
      }
      long long int ww = (ans * (s[i - 1] - '0')) % 1000000007;
      long long int vv = (2 * 1000000007 - i * (s[i - 1] - '1')) % 1000000007;
      ans = (ww + vv) % 1000000007;
    }
    cout << ans << "\n";
  }
  cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
  return 0;
}
