#include <bits/stdc++.h>
using namespace std;
char s[1000007];
int n;
inline void write(int p, int d) {
  if (n >= (1000007 - 7)) return;
  int v = n;
  for (register int j = (0); j < (d); j++)
    for (register int i = (p); i < (v); i++) {
      s[n++] = s[i];
      if (n >= (1000007 - 7)) return;
    }
  s[n] = 0;
}
int main() {
  int t;
  scanf("%d", &t);
  while (0 < t--) {
    int x;
    scanf("%d", &x);
    scanf("%s", s);
    n = strlen(s);
    int ans = n;
    for (register int l = (1); l <= (x); l++) {
      int t = s[l - 1] - '1';
      write(l, t);
      ans =
          ((long long)ans + (long long)(ans - l) * t % 1000000007) % 1000000007;
      if (ans < 0) ans += 1000000007;
    }
    printf("%d\n", ans % 1000000007);
  }
}
