#include <bits/stdc++.h>
using namespace std;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
constexpr long long TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T, class U>
void chmin(T& t, const U& u) {
  if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
  if (t < u) t = u;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{";
  for (int i = 0; i < (v.size()); i++) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}
const long long MOD = TEN(9) + 7;
int main() {
  int TC;
  cin >> TC;
  while (TC--) {
    int x;
    string s;
    cin >> x >> s;
    long long len = s.size();
    bool flg = (s.size() >= x);
    for (int i = 0; i < (x); i++) {
      int num = s[i] - '0';
      if (!flg) {
        int cl = s.size();
        for (int tt = 0; tt < (num - 1); tt++) {
          for (int j = i + 1; j < cl; ++j) {
            s.push_back(s[j]);
          }
        }
        len = s.size();
        if (len >= x) {
          flg = 1;
        }
      } else {
        len += (num - 1) * (len - i - 1);
        len %= MOD;
        if (len < 0) len += MOD;
      }
    }
    printf("%lld\n", len);
  }
  return 0;
}
