#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9 + 7;
char S[5000006];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int x;
    cin >> x >> S + 1;
    int N = strlen(S + 1);
    ll cnt = N;
    int flag = 0;
    for (int i = 1; i <= x; ++i) {
      int t = S[i] - '0';
      flag |= (cnt > x);
      if (!flag) {
        int sz = cnt;
        for (int j = 1; j < t; ++j) {
          for (int k = i + 1; k <= sz; ++k) S[++cnt] = S[k];
        }
      } else
        cnt = ((i + t * (cnt - i)) % mod + mod) % mod;
    }
    printf("%lld\n", cnt);
  }
  return 0;
}
