#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long nm = 0;
  bool fh = true;
  char cw = getchar();
  for (; !isdigit(cw); cw = getchar()) fh ^= (cw == '-');
  for (; isdigit(cw); cw = getchar()) nm = nm * 10 + (cw - '0');
  return fh ? nm : -nm;
}
namespace CALC {
inline int add(int x, int y) {
  return (x + y >= 1000000007) ? (x + y - 1000000007) : (x + y);
}
inline int mns(int x, int y) {
  return (x - y < 0) ? (x - y + 1000000007) : (x - y);
}
inline int mul(int x, int y) {
  return (long long)x * (long long)y % 1000000007;
}
inline void upd(int &x, int y) {
  x += y;
  (x >= 1000000007) ? (x -= 1000000007) : 0;
}
inline void dec(int &x, int y) {
  x -= y;
  (x < 0) ? (x += 1000000007) : 0;
}
inline int qpow(int x, int sq) {
  int res = 1;
  for (; sq; sq >>= 1, x = mul(x, x))
    if (sq & 1) res = mul(res, x);
  return res;
}
}  // namespace CALC
using namespace CALC;
int n, m, p[2002000];
char ch[2002000];
inline int solve() {
  m = read(), scanf("%s", ch + 1), n = strlen(ch + 1);
  int ans = n, mx = n;
  for (int i = 1; i <= n; i++) p[i] = ch[i] - '0';
  int x = 0;
  while (x < m) {
    ++x;
    if (mx < 2002000) {
      for (int i = 1; i <= (mx - x) * (p[x] - 1); ++i) {
        if (i + mx >= 2002000) break;
        p[i + mx] = p[i + mx - (mx - x)];
      }
    }
    upd(ans, mul(p[x] - 1, mns(ans, x)));
    mx = min(mx + (p[x] - 1) * (mx - x), 2002000);
  }
  return ans;
}
int main() {
  for (int Cas = read(); Cas; --Cas) printf("%d\n", solve());
  return 0;
}
