#include <bits/stdc++.h>
using namespace std;
char s[5000005];
int main() {
  long long test, i, x, j, k, curr;
  bool done;
  long long ans, mod = 1000000007;
  scanf("%lld", &test);
  while (test--) {
    done = false;
    scanf("%lld", &x);
    scanf(" %s", s);
    ans = strlen(s);
    curr = strlen(s);
    for (i = 1; i <= x; i++) {
      if (!done) {
        for (k = 1; k < s[i - 1] - '0'; k++)
          for (j = i + 1; j <= curr; j++) s[ans++] = s[j - 1];
        if (ans > x) done = true;
        curr = ans;
      } else {
        ans = i + (ans - i) * (long long)(s[i - 1] - '0');
        ans %= mod;
        ans = (ans + mod) % mod;
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
