#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const long long M = 1e9 + 7;
long long a[N];
int main() {
  int x, T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &x);
    string s;
    cin >> s;
    a[0] = s.size() % M;
    bool f = 0;
    for (long long i = 1; i <= x; ++i) {
      if (!f) {
        for (int j = 1; j < (s[i - 1] - '0'); ++j)
          s += s.substr(i, a[i - 1] - i);
      }
      if (s[i - 1] == '1')
        a[i] = a[i - 1];
      else
        a[i] = ((i % M) + (((a[i - 1] - i) % M) * (s[i - 1] - '0')) % M) % M;
      if (a[i] >= x) f = 1;
    }
    printf("%lld\n", (a[x] + M) % M);
  }
  return 0;
}
