#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "{" << p.first << "," << p.second << "}";
  return os;
}
const long long N = 3e5 + 5;
const long long oo = 1e9 + 7;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long T, cs = 0;
  cin >> T;
  while (T--) {
    long long x;
    cin >> x;
    string s;
    cin >> s;
    long long r = s.size();
    long long now = x;
    for (long long i = 0; i < x; i++) {
      r = (r - 1 + oo) % oo;
      char c = s[i] - '0';
      r = (r * c) % oo;
      c--;
      now = s.size();
      while (c--) {
        for (long long j = i + 1; j < now and s.size() < x; j++) s += s[j];
      }
    }
    cout << (x + r) % oo << "\n";
  }
}
