#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string y;
    cin >> y;
    long long i, j;
    long long len = y.length();
    i = 1;
    while (y.length() < n) {
      string w = y.substr(i, len);
      for (j = 1; j < y[i - 1] - '0'; j++) {
        y.append(w);
      }
      len = (len + ((y[i - 1] - '1') * ((len - i) % 1000000007)) % 1000000007) %
            1000000007;
      i++;
    }
    while (i <= n) {
      len = (len + ((y[i - 1] - '1') * ((len - i + 1000000007) % 1000000007)) %
                       1000000007) %
            1000000007;
      i++;
    }
    cout << len << endl;
    y.clear();
  }
}
