#include <bits/stdc++.h>
using namespace std;
string sss;
char s[1000005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    long long a, b, c, d, e, f, i, j, k, m, n, o, x, y;
    sss.clear();
    cin >> k >> sss;
    long long ans = sss.size();
    long long end = 0;
    for (char c : sss) s[end++] = c;
    bool flag = true;
    for (i = 0; i < k; i++) {
      a = s[i] - '1';
      if (flag) {
        int nn = a;
        int an = end;
        while (nn--) {
          for (j = i + 1; j < an; j++) {
            s[end++] = s[j];
            if (end >= k) {
              flag = false;
              break;
            }
          }
          if (!flag) break;
        }
      }
      long long plu = ans - (i + 1);
      plu += (long long)(1e9 + 7);
      plu %= (long long)(1e9 + 7);
      ans += (a * plu);
      ans %= (long long)(long long)(1e9 + 7);
    }
    cout << ans % (long long)(1e9 + 7) << "\n";
  }
}
