#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int x;
    cin >> x;
    string s;
    cin >> s;
    string mark = s;
    int tp = 0;
    while ((int)mark.length() < x) {
      int tem = mark[tp] - '0';
      tem--;
      string be = mark.substr(tp + 1);
      while (tem--) mark = mark + be;
      tp++;
    }
    long long int res = (long long int)s.length();
    long long int m = 1000000007;
    for (int i = 0; i < x; ++i) {
      int tem = mark[i] - '0';
      tem--;
      res = res + (res - (i + 1)) * tem;
      res = res % m;
    }
    cout << res << "\n";
  }
}
