#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
  os << "[ ";
  for (auto v : V) os << v << " ";
  os << "]";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, set<T> second) {
  os << "{ ";
  for (auto s : second) os << s << " ";
  return os << "}";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class L, class R>
ostream& operator<<(ostream& os, map<L, R> M) {
  os << "{ ";
  for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
  return os << "}";
}
const long long M = 1e9 + 7;
long long x, l, tot, lim;
string s;
void solve() {
  cin >> x;
  cin >> s;
  l = 1;
  tot = s.size();
  while (true) {
    lim = s.size();
    tot = (tot + ((s[l - 1] - '0' - 1) * (tot - l))) % M;
    if (l >= s.size() || l >= x) break;
    for (long long i = 0; i < s[l - 1] - '0' - 1; i++) {
      for (long long j = l; j < lim; j++) {
        s.push_back(s[j]);
        if (s.size() >= x) {
          for (long long k = l + 1; k <= x; k++)
            tot = (tot + ((s[k - 1] - '0' - 1) * (tot - k))) % M;
          cout << ((tot % M) + M) % M << "\n";
          return;
        }
      }
    }
    l++;
  }
  cout << ((tot % M) + M) % M << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  long long T;
  cin >> T;
  while (T--) solve();
  return 0;
}
