#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const double PI = 2 * acos(0.0);
const double eps = 1e-9;
int main() {
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    long long x;
    long long n;
    string s;
    cin >> x;
    cin >> s;
    n = ((int)s.size());
    const long long MOD = 1000000007;
    for (int i = 1; i <= (int)(x); ++i) {
      if (((int)s.size()) <= x) {
        string tmp = s.substr(i);
        for (int j = 1; j < (int)(s[i - 1] - '0'); j++) {
          s += tmp;
        }
      }
      n = (i + (n + MOD - i) * (s[i - 1] - '0')) % MOD;
    }
    cout << n << endl;
  }
}
