#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 100;
const int INF = 0x3f3f3f3f;
inline long long fpow(long long a, long long b) {
  long long r = 1, t = a;
  while (b) {
    if (b & 1) r = (r * t) % MOD;
    b >>= 1;
    t = (t * t) % MOD;
  }
  return r;
}
int pre[MAXN], x, X;
char str[1100];
int main() {
  int T;
  cin >> T;
  while (T--) {
    scanf("%d %s", &x, str);
    long long sz = strlen(str);
    for (int i = 0; i < sz; i++) pre[i] = str[i] - '0';
    long long ans = sz, cnt = 0;
    while (ans < x) {
      int num = pre[cnt++], scnt = ans;
      X = ans;
      sz = ans - cnt;
      ans = cnt + num * sz;
      for (int j = 0; j < num - 1; j++) {
        for (int k = cnt; k < scnt; k++) {
          if (X >= x) break;
          pre[X++] = pre[k];
        }
      }
    }
    while (cnt < x) {
      long long num = pre[cnt++];
      sz = (ans - cnt + MOD) % MOD;
      ans = ((cnt % MOD) + (num * sz) % MOD) % MOD;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
