#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long int x;
    cin >> x;
    string s;
    cin >> s;
    long long int l = 1;
    while (s.size() < x) {
      int r = s[l - 1] - '0';
      string rep;
      rep.assign(s.begin() + l, s.end());
      for (int i = 1; i < r; i++) s += rep;
      l++;
    }
    long long int out = s.size();
    while (l <= x) {
      out = l + (out - l) * (s[l - 1] - '0');
      l++;
      out %= 1000000007;
    }
    cout << (out + 1000000007) % 1000000007 << endl;
  }
}
