#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int maxn = 1100;
const long long linf = 1e18;
const int inf = 0x3f3f3f3f;
long long qpow(long long a, long long b) {
  return b ? ((b & 1) ? a * qpow(a * a % MOD, b >> 1) % MOD
                      : qpow(a * a % MOD, b >> 1)) %
                 MOD
           : 1;
}
long long qpow(long long a, long long b, long long c) {
  return b ? ((b & 1) ? a * qpow(a * a % MOD, b >> 1) % c
                      : qpow(a * a % MOD, b >> 1)) %
                 c
           : 1;
}
inline int ird() {
  register int x = 0, f = 1;
  register char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * f;
}
inline long long lrd() {
  register long long x = 0, f = 1;
  register char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * f;
}
int gcd(int a, int b) { return (b > 0) ? gcd(b, a % b) : a; }
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int f = 0;
    while (s.length() < n) {
      int len = s.length();
      for (int j = 0; j < s[f] - '1'; j++) {
        s += s.substr(f + 1, len - f - 1);
      }
      f++;
    }
    long long last = s.length();
    while (f < n) {
      last = (last + 1ll * (s[f] - '1') * (last - 1ll - 1ll * f) % MOD + MOD) %
             MOD;
      f++;
    }
    cout << last << endl;
  }
  return 0;
}
