#include <bits/stdc++.h>
using namespace std;
const int MN = 1e6 + 12;
const long long MOD = 1e9 + 7;
void solve() {
  long long x;
  cin >> x;
  string s;
  cin >> s;
  long long ans = s.length();
  for (long long i = 0; i < x; i++) {
    long long val = s[i] - '0';
    if (s.size() < x) {
      string sf(s.begin() + i + 1, s.end());
      for (long long j = 0; j < val - 1; j++) {
        for (char c : sf) s.push_back(c);
      }
    }
    ans = (ans + (ans - i - 1) * (val - 1) % MOD) % MOD;
  }
  ans = (ans % MOD + MOD) % MOD;
  cout << ans << "\n";
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
