#include <bits/stdc++.h>
using namespace std;
const long long int M = 1000000007;
const long long int M1 = 998244353;
const long long int M2 = 1000000000000000001;
long long int mod(long long int x) { return (x % M); }
long long int mod_minus(long long int a, long long int b) {
  long long int ans = (mod(a) - mod(b));
  if (ans < 0) ans = mod(ans + M);
  return ans;
}
long long int mod_mul(long long int a, long long int b) {
  return mod(mod(a) * mod(b));
}
long long int mod_add(long long int a, long long int b) {
  return mod(mod(a) + mod(b));
}
long long int ceill(long long int a, long long int b) {
  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}
long long int extended_gcd(long long int a, long long int b, long long int &x,
                           long long int &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long int x1, y1, ans = extended_gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return ans;
}
long long int power_mod(long long int a, long long int b, long long int m) {
  long long int ans = 1;
  while (b != 0) {
    if (b % 2 == 1) ans = (ans * a) % m;
    a = a * a;
    a %= m;
    b /= 2;
  }
  return ans;
}
long long int mod_inverse(long long int a, long long int m) {
  return power_mod(a, m - 2, m);
}
void mod_inverse_array(long long int inv[], long long int u, long long int m) {
  inv[1] = 1;
  for (long long int i = 2; i <= u; i++) {
    inv[i] = ((-(m / i) * inv[m % i] % m) + m) % m;
  }
}
long long int N_C_r_mod_m(long long int N, long long int r,
                          long long int factorial[]) {
  long long int a = factorial[N], b = mod_inverse(factorial[N - r], M),
                c = mod_inverse(factorial[r], M);
  return ((a * b) % M * c) % M;
}
void prime_factorization(long long int n,
                         unordered_map<long long int, long long int> &m) {
  long long int i;
  for (i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      m[i]++;
      n = n / i;
    }
  }
  if (n != 1) m[n]++;
}
void linear_sieve(vector<long long int> &pr, long long int lp[],
                  long long int N) {
  for (long long int i = 2; i <= N; ++i) {
    if (lp[i] == 0) {
      lp[i] = i;
      pr.push_back(i);
    }
    for (long long int j = 0;
         j < (long long int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j)
      lp[i * pr[j]] = pr[j];
  }
}
void solve() {
  long long int x;
  cin >> x;
  string s;
  cin >> s;
  s = 'a' + s;
  string ss = s;
  long long int l = 0;
  while (s.size() <= x) {
    l++;
    long long int k = s[l] - '0';
    string s1 = s.substr(l + 1, s.size());
    for (long long int i = 0; i < k - 1; i++) {
      s += s1;
    }
  }
  l = 0;
  long long int c = ss.size() - 1;
  while (l < x) {
    l++;
    c = mod_add(c, mod_mul(s[l] - '0' - 1, mod_minus(c, l)));
  }
  cout << c << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) solve();
}
