#include <bits/stdc++.h>
using namespace std;
bool isprime(long long int n) {
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
const long long int cnst = 1e9 + 7, di = 998244353;
bool IsQuery = true, found = false;
long long int q = 1, cnt, n, k;
set<long long int> factors(long long int n);
map<int, vector<long long int> > connected;
map<int, bool> occured;
vector<long long int> len;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
string s, t;
void solve() {
  long long int d, x, y = 0, z = 0, minm = cnst, maxm = 1, sum = 0, l, flag = 0,
                      val, ans = 0;
  map<long long int, long long int> m, f;
  set<long long int> set;
  vector<long long int> a, b, v;
  cin >> x >> s;
  l = s.size();
  while (y < x) {
    y++;
    d = s[z++] % 48 - 1;
    k = (l - y) % cnst;
    if (k < 0) k += cnst;
    if (!flag) {
      s.erase(s.begin());
      t = s;
      z--;
    }
    while (!flag && d) {
      s += t;
      l += k;
      if (l >= x) flag = 1;
      l %= cnst;
      d--;
    }
    l += (d * k) % cnst;
    l %= cnst;
  }
  cout << l << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  if (IsQuery) cin >> q;
  for (int i = 0; i < q; i++) solve();
  return 0;
}
set<long long int> factors(long long int n) {
  set<long long int> f;
  for (long long int x = 2; x * x <= n; x++) {
    while (n % x == 0) {
      f.insert(x);
      n /= x;
    }
  }
  if (n > 1) f.insert(n);
  return f;
}
