#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read(T& x) {
  x = 0;
  int f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x = f ? -x : x;
}
const int P = 1e9 + 7;
const int N = 3e6 + 10;
int T, x;
char s[N];
int main() {
  for (read(T); T--;) {
    read(x);
    scanf("%s", s + 1);
    int len = strlen(s + 1);
    int len2 = len;
    for (int i = 0; i < x; ++i) {
      int cnt = s[i + 1] - '0';
      cnt -= 1;
      for (int j = 1; j <= cnt; ++j) {
        if (len2 >= x) {
          break;
        } else {
          int cnt = len2;
          for (int k = i + 2; k <= len2; ++k) {
            s[++cnt] = s[k];
          }
          len2 = cnt;
          s[len2 + 1] = '\0';
        }
      }
      if (cnt) len = (len + 1LL * cnt * (len - i - 1) % P) % P;
      if (len < 0) len += P;
    }
    printf("%d\n", len);
  }
  return 0;
}
