#include <bits/stdc++.h>
using namespace std;
char op[1 << 23];
char bas[1 << 23];
const int MOD = 1e9 + 7;
void solve() {
  int maxn, tim;
  scanf("%d%s", &tim, op + 1);
  maxn = strlen(op + 1);
  long long ans = maxn;
  for (int i = 1; i <= tim; i++) {
    ans = 1LL * (1LL * ans + (op[i] - '1') * (ans - i)) % MOD;
    if (maxn >= tim) continue;
    int tp = 0;
    for (int j = 1; j < op[i] - '0'; j++)
      for (int k = i + 1; k <= maxn; k++) bas[++tp] = op[k];
    for (int j = 1; j <= tp && maxn < tim; j++) op[++maxn] = bas[j];
  }
  if (ans < 0) ans += MOD;
  printf("%lld\n", ans);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}
