#include <bits/stdc++.h>
using namespace std;
template <class K>
inline bool cmax(K& a, const K& b) {
  return (a < b) ? a = b, 1 : 0;
}
template <class K>
inline bool cmin(K& a, const K& b) {
  return (a > b) ? a = b, 1 : 0;
}
inline int read() {
  register int s = 0;
  register char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) s = (s << 1) + (s << 3) + c - '0', c = getchar();
  return s;
}
int n, T, m;
long long t;
char s[7000007];
int main() {
  register int i, j, flg;
  char k;
  T = read();
  while (T--) {
    m = read(), scanf("%s", s + 1), t = strlen(s + 1), flg = 1;
    for (i = 1; i <= m; i++) {
      if (s[i] == '1') continue;
      if (t < m && flg) {
        n = t;
        for (k = '2'; k <= s[i]; ++k)
          for (j = i + 1; j <= n; j++) s[++t] = s[j];
      } else {
        flg = 0;
        t = (t + (t - i) * (s[i] - '1')) % 1000000007;
      }
    }
    printf("%d\n", (t % 1000000007 + 1000000007) % 1000000007);
  }
  return 0;
}
