#include <bits/stdc++.h>
using namespace std;
long long i, j, k, m, n, t, x;
string s, u;
int main() {
  for (scanf("%lld", &t); t--;) {
    i = 1;
    cin >> x >> s;
    for (; s.size() < x; i++) {
      if (s[i - 1] > 49) {
        u = s.substr(i);
        for (k = s[i - 1] - 48; --k;) s += u;
      }
    }
    m = s.size();
    for (; i <= x; i++)
      m = (m + (s[i - 1] - 49) * (m - i + 1000000007)) % 1000000007;
    cout << m << endl;
  }
}
