#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
long long power(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y / 2, x = (x * x) % 1000000007;
  }
  return res % 1000000007;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long x;
    cin >> x;
    string s;
    cin >> s;
    vector<char> arr;
    for (auto v : s) arr.emplace_back(v);
    long long i;
    long long curr = s.length();
    for (i = 1; i <= x; i++) {
      if (arr.size() <= x + 5) {
        long long pp = arr.size();
        for (long long j = 0; j < (arr[i - 1] - '0') - 1; j++) {
          for (long long k = i; k < pp; k++) {
            arr.emplace_back(arr[k]);
            if (arr.size() >= x + 2) break;
          }
        }
      }
      curr = i + (curr - i + 1000000007) * (arr[i - 1] - '0') % 1000000007;
      curr %= 1000000007;
    }
    cout << curr << "\n";
  }
}
