#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;
    bool f = 0;
    for (int i = 1; i <= x; ++i) {
      int cnt = s[i] - '0';
      cnt -= 1;
      if (f || len >= x) {
        f = 1;
        len = (len + 1LL * cnt * (len - i) % P) % P;
        if (len < 0) len += P;
      } else {
        if (cnt == 1) {
          int x = len;
          for (int j = i + 1; j <= x; ++j) s[++len] = s[j];
        } else if (cnt == 2) {
          int x = len;
          for (int j = i + 1; j <= x; ++j) s[++len] = s[j];
          for (int j = i + 1; j <= x; ++j) s[++len] = s[j];
        }
      }
    }
    printf("%d\n", len);
  }
  return 0;
}
