#include <bits/stdc++.h>
using namespace std;
long long t, x, ans, len;
const long long mod = 1e9 + 7;
string s;
signed main() {
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld", &x);
    cin >> s;
    ans = s.length();
    for (long long i = 0; i < x; i++)
      if (s.length() < x) {
        len = s.length();
        for (long long j = 0; j <= s[i] - '2'; j++)
          for (long long k = i + 1; k < len; k++) s += s[k];
        ans = s.length();
      } else
        ans = (ans + (ans - i - 1 + mod) * (s[i] - '1')) % mod;
    printf("%d\n", ans);
  }
  return 0;
}
