#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int x;
    cin >> x;
    string s;
    cin >> s;
    string xx;
    xx = s;
    long long int l = 0;
    while (xx.size() < x) {
      string temp = xx.substr(l + 1);
      for (long long int ii = 1; (ii < (xx[l] - '0')) && (xx.size() < x); ii++)
        xx += temp;
      l++;
    }
    vector<long long int> ans(x + 1, 0);
    ans[0] = 1 + (s.size() - 1) * (xx[0] - '0');
    ans[0] %= 1000000007;
    for (long long int i = 1; i < x; i++) {
      ans[i] = ((ans[i - 1] % 1000000007 - (i + 1) % 1000000007) % 1000000007) *
                   (xx[i] - '0') % 1000000007 +
               (i + 1) % 1000000007;
      ans[i] %= 1000000007;
      while (ans[i] < 0) ans[i] += 1000000007;
    }
    cout << ans[x - 1] << endl;
  }
}
