#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 6;
const int INF = 1e9;
const long long MOD = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long x;
    cin >> x;
    string s, alu;
    cin >> s;
    long long n = s.size();
    for (long long i = 1; i <= x; i++) {
      long long rem = (long long)s.size() - i;
      for (long long j = 0;
           j < rem * (s[i - 1] - '0' - 1) and (int) s.size() <= x; j++) {
        s.push_back(s[(j % rem) + i]);
      }
      long long k = s[i - 1] - '0', left = (n - i + MOD) % MOD;
      n = (i + ((k * left) % MOD)) % MOD;
    }
    cout << n << "\n";
  }
}
