#include <bits/stdc++.h>
using namespace std;
bool rev(long long x, long long y) { return x > y; }
void input_arr(long long a[], long long n) {
  for (long long i = 0; i < n; i += 1) cin >> a[i];
}
bool sortbysec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return a.second < b.second;
}
bool sortinrev(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.first > b.first);
}
void print_vec(vector<long long> &v) {
  for (auto i : v) cout << i << " ";
  cout << '\n';
}
bool sortinrevbysec(const pair<long long, long long> &a,
                    const pair<long long, long long> &b) {
  return (a.second > b.second);
}
void print_arr(long long a[], long long n) {
  for (long long i = 0; i < n; i += 1) cout << a[i] << " ";
  cout << '\n';
}
template <typename... T>
void input(T &...args) {
  ((cin >> args), ...);
}
template <typename... T>
void print(T &&...args) {
  ((cout << args << '\n'), ...);
}
template <typename... T>
void deb(T &&...args) {
  cout << "~~ ";
  ((cout << args << " "), ...);
  cout << '\n';
}
void stand8th() {
  long long x;
  input(x);
  string s;
  input(s);
  long long ans = 0;
  long long val = (long long)(s.size()) - 1;
  long long M = 1000000007;
  for (long long i = 0; i < x; i += 1) {
    if (i == 0) {
      val = (val % M * ((long long)(s[i] - '0')) % M) % M;
    } else {
      val--;
      val = (val % M * ((long long)(s[i] - '0')) % M) % M;
    }
    if ((long long)(s.size()) < x) {
      string ss = s.substr(i + 1);
      long long f = (long long)(s.size());
      for (long long j = 0; j < (long long)(s[i] - '0') - 1; j += 1) {
        for (long long j = 0; j < (long long)(ss.size()); j += 1) {
          f++;
          s += ss[j];
          if (f >= x) break;
        }
        if (f >= x) {
          break;
        }
      }
    }
  }
  print((val + x) % M);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long tin = 1;
  input(tin);
  while (tin--) {
    stand8th();
  }
  return 0;
}
