#include <bits/stdc++.h>
using namespace std;
struct Solution {
  int t, x, len, i;
  int ans;
  static const long long mod = 1e9 + 7;
  char s[1000007];
  inline void update(int rep, int unt) { ans = (i + 1ll * rep * unt) % mod; }
  inline bool cpy(int unt, int cnt) {
    for (int j = len; j < len + unt * cnt; ++j) {
      if (j > x) return false;
      s[j] = s[(j - len) % unt + i];
    }
    return true;
  }
  inline void Solve() {
    scanf("%d", &t);
    while (t--) {
      scanf("%d", &x);
      scanf("%s", s);
      ans = len = strlen(s);
      for (i = 1; i <= x; ++i) {
        int l = len - i;
        int val = s[i - 1] - '0';
        update(val, ans - i + mod);
        if (cpy(l, val - 1))
          len = i + val * l;
        else
          len = x;
      }
      printf("%d\n", ans);
    }
  }
} CF607C;
signed main() {
  CF607C.Solve();
  return 0;
}
