#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxn = 1e5 + 5;
void solve() {
  long long first;
  cin >> first;
  string s;
  cin >> s;
  long long ans = (long long)((s).size());
  for (long long i = 0; i < first; i++) {
    long long len = ans;
    long long t = s[i] - '0';
    long long m = (long long)((s).size());
    for (long long _ = 0; _ < t - 1; _++) {
      ans += (len - i - 1 + mod) % mod;
      ans %= mod;
      for (long long j = i + 1; j < m; j++) {
        if ((long long)((s).size()) > first) break;
        s += s[j];
      }
    }
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long tc = 1;
  cin >> tc;
  while (tc--) {
    solve();
  }
  return 0;
}
