#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, mod = 1000000007;
  cin >> t;
  vector<long long> ans;
  for (int i = 0; i < t; i++) {
    long long x, sum = 0, si = 0;
    cin >> x;
    string s;
    cin >> s;
    sum = s.length();
    while (s.length() < x) {
      long long k = (s[si] - '0') - 1, sl = s.length();
      sum += (k * (s.length() - 1 - si));
      sum %= mod;
      for (int i = 0; i < k; i++) {
        for (int j = si + 1; j < sl; j++) {
          s += s[j];
        }
      }
      si++;
    }
    long long sl = s.length();
    while (si < x) {
      long long k = (s[si] - '0') - 1;
      if ((k * (sl - 1 - si)) >= 0) {
        sum += (k * (sl - 1 - si));
        sl += (k * (sl - 1 - si));
      } else {
        sum += (k * (mod + sl - 1 - si));
        sl += (k * (mod + sl - 1 - si));
      }
      sl %= mod;
      sum %= mod;
      si++;
    }
    ans.push_back(sum);
  }
  for (int i = 0; i < t; i++) cout << ans[i] << endl;
  return 0;
}
