#include <bits/stdc++.h>
using namespace std;
int t, n, m;
long long now, ans;
char ch[1000039];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d %s", &m, ch + 1);
    n = ans = strlen(ch + 1), now = n - 1;
    for (int a = 1; a <= m; a++) {
      for (int b = 1, c = n; b < ch[a] - '0'; b++) {
        (ans += now) %= 1000000007;
        for (int d = a + 1; d <= c && n < m; d++) {
          ch[++n] = ch[d];
        }
      }
      (now *= ch[a] - '0') %= 1000000007;
      ((--now) += 1000000007) %= 1000000007;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
