#include <bits/stdc++.h>
using namespace std;
long long las[200], fir[200];
long long x, mod = 1000000007, sz, ind, cur, k;
string second;
int main() {
  ios::sync_with_stdio(false);
  long long t;
  cin >> t;
  while (t--) {
    cin >> x >> second;
    sz = (long long)second.size();
    ind = 0;
    long long ok = 0;
    while (true) {
      if (!ok) {
        cur = second[ind] - '0' - 1;
        k = (int)second.size();
        sz += cur * (sz - ind - 1LL);
        sz %= mod;
        while (cur--)
          for (int i = ind + 1; i < k; i++) {
            if ((int)second.size() > x) {
              ok = 1;
              break;
            }
            second += second[i];
          }
      } else {
        cur = second[ind] - '0' - 1;
        sz += cur * (sz - ind - 1LL);
        sz %= mod;
      }
      if (ind == x - 1) break;
      ind++;
    }
    cout << (sz + mod) % mod << '\n';
  }
  return 0;
}
