#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int x;
    cin >> x;
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
      v.push_back(s[i] - '0');
    }
    long long int maxi = x + 5;
    long long int mod = 1000000007;
    long long int ans = v.size();
    long long int l = 0;
    while (l < x) {
      l++;
      long long int len = v.size();
      long long int cut = ans - l;
      cut = cut % mod;
      cut = (cut + mod) % mod;
      ans = l;
      ans += cut * (v[l - 1]);
      ans = ans % mod;
      ans = (ans + mod) % mod;
      for (int j = 1; j < v[l - 1]; j++) {
        if (v.size() < maxi) {
          for (int i = l; i <= (len - 1); i++) {
            if (v.size() < maxi) v.push_back(v[i]);
          }
        }
      }
    }
    ans = ans % mod;
    ans = (ans + mod) % mod;
    cout << ans << endl;
    v.clear();
  }
  return 0;
}
