#include <bits/stdc++.h>
using namespace std;
const long long MAXVAL = (long long)1e18 + 1;
const long long MOD = 1000000007ll;
long long poww(int x, long long pow) {
  if (pow == 0ll) return 1;
  if (pow == 1ll) return x % MOD;
  long long ans = poww(x, pow >> 1) % MOD;
  ans = (ans * ans) % MOD;
  if ((pow & 1) == 1) {
    ans = (ans * x) % MOD;
  }
  return ans % MOD;
}
long long gcd(long long x, long long y) {
  if (x == 0) return y;
  while (y) {
    x %= y;
    swap(x, y);
  }
  return x;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q = 1;
  bool debug = true;
  cin >> q;
  while (q-- > 0) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    long long curlen = s.length();
    for (int l = 0; l < n; ++l) {
      assert(l < s.length());
      int cur = s[l] - '0';
      long long newlen = (l + 1 + cur * (MOD + curlen - l - 1)) % MOD;
      if (s.length() < n) {
        string sub = s.substr(l + 1, (long long)s.length() - l - 1);
        string ss = "";
        for (int j = 1; s.length() + ss.length() < n && j < cur; ++j)
          ss = ss + sub;
        s += ss;
      }
      curlen = newlen;
    }
    cout << curlen << "\n";
  }
  return 0;
}
