#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5, mod = 1e9 + 7;
vector<char> s;
long long X;
void paste(long long p, long long l, long long cnt) {
  if (s.size() > X + 3 || l == 0) return;
  for (long long i = 0; i < cnt; ++i)
    for (long long j = 0; j < l; ++j)
      if (s.size() > X + 3)
        return;
      else
        s.push_back(s[p + j]);
}
long long md(long long a) {
  if (a < 0)
    return (a + mod * 2) % mod;
  else
    return a % mod;
}
void solve() {
  long long x;
  cin >> x;
  X = x;
  string str;
  cin >> str;
  s = vector<char>(str.begin(), str.end());
  long long p = 0;
  long long cl = s.size();
  while (p < x) {
    ++p;
    long long num = s[p - 1] - '0';
    paste(p, s.size() - p, num - 1);
    cl = (cl + (num - 1) * md(cl - p)) % mod;
  }
  cout << cl << endl;
  return;
}
signed main() {
  ios::sync_with_stdio(false);
  long long t;
  cin >> t;
  for (long long i = 0; i < t; ++i) solve();
  return 0;
}
