#include <bits/stdc++.h>
using namespace std;
int x;
string s, c;
int main() {
  ios::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> x >> s;
    long long n = s.size();
    long long sl = 0;
    int l = 0;
    while (l < x) {
      l++;
      sl = s[l - 1] - '0';
      if (s.size() <= x) {
        if (sl > 1) {
          c = s.substr(l, (int)s.size() - l);
          for (int i = 1; i < sl; i++) {
            s += c;
          }
          n = s.size();
        }
      } else {
        long long csz = n - l;
        if (csz < 0) csz += 1000000007;
        n += csz * (sl + 1000000007 - 1);
        n %= 1000000007;
      }
      if (l == x) break;
    }
    cout << n << '\n';
  }
}
