#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int res = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (isdigit(ch)) {
    res = res * 10 + ch - '0';
    ch = getchar();
  }
  return res * f;
}
namespace qiqi {
const int N = 1e6 + 5, P = 1e9 + 7;
int n, m;
char s[N];
void main() {
  m = read();
  scanf("%s", s + 1);
  int x = n = strlen(s + 1);
  for (int i = (1); i <= (m); ++i) {
    int k = (x - i + P) % P;
    for (int j = (1); j <= (min(1LL * (s[i] - '1') * k, 1LL * m)); ++j) {
      if (n >= m) break;
      ++n;
      s[n] = s[n - k];
    }
    x = (x + 1LL * k * (s[i] - '1') % P) % P;
  }
  printf("%d\n", (x + P) % P);
}
}  // namespace qiqi
int main() {
  int T = read();
  while (T--) qiqi::main();
  return 0;
}
