#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const double PI = acos(-1);
template <class A, class B>
std::ostream& operator<<(std::ostream& st, const std::pair<A, B> p) {
  st << "(" << p.first << ", " << p.second << ")";
  return st;
}
using namespace std;
const int mod = 1e9 + 7;
int add(int a, int b) {
  a += b;
  if (a >= mod) a -= mod;
  if (a < 0) a += mod;
  return a;
}
int mul(int a, int b) { return (a * (long long)b) % mod; }
char buffer[1 << 20];
string S;
int n, x;
int solve() {
  n = S.size();
  if (n == 1) return 1;
  int l = 0;
  int len = ((int)S.size());
  while (((int)S.size()) < x) {
    l++;
    int num = S[l - 1] - '0';
    num--;
    int s = l, e = ((int)S.size());
    while (((int)S.size()) < x && num) {
      num--;
      for (int i = s; i < e; i++) S.push_back(S[i]);
    }
    len = add(((int)S.size()), mul(num, e - s));
  }
  for (; l < x;) {
    l++;
    int pref_val = S[l - 1] - '0';
    int suff_len = add(len, -l);
    len = add(l, mul(pref_val, suff_len));
  }
  return len;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d %s", &x, buffer);
    S = string(buffer);
    printf("%d\n", solve());
  }
  return 0;
}
