#include <bits/stdc++.h>
using namespace std;
const int N = 1e8 + 5;
const long long mod = 1e9 + 7;
long long n, x;
char s[N];
long long getans(long long ans) { return (ans % mod + mod) % mod; }
void solve() {
  scanf("%lld%s", &x, s + 1);
  long long now = 0, len = strlen(s + 1);
  n = len;
  while (len < x) {
    ++now;
    long long x = s[now] - '0', tot = (x - 1) * (len - now);
    long long l = now + 1, r = len;
    for (int i = len + 1; i <= len + tot; i++) {
      if (l > r) l = now + 1;
      s[i] = s[l];
      ++l;
    }
    len += tot;
  }
  long long ans = 0;
  for (int i = now + 1; i <= x; i++) {
    ans = i + 1ll * (s[i] - '0') * (len - i) % mod;
    len += 1ll * (s[i] - '0' - 1ll) * (len - i) % mod;
    len = (len % mod + mod) % mod;
  }
  printf("%lld\n", (ans % mod + mod) % mod);
}
int main() {
  int cs;
  scanf("%d", &cs);
  while (cs--) solve();
}
