#include <bits/stdc++.h>
using namespace std;
long long bpow(long long a, long long b, long long abs);
long long bis(long long ar[], long long l, long long r, long long x);
long long mindig(long long x);
long long maxdig(long long x);
void Fast();
long long bpow(long long a, long long b, long long modi) {
  a %= modi;
  long long res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a % modi;
    }
    a = a * a % modi;
    b >>= 1;
  }
  return res;
}
long long bis(long long ar[], long long l, long long r, long long x) {
  while (l <= r) {
    long long m = l + (r - l) / 2;
    if (ar[m] == x) {
      return m;
    }
    if (ar[m] < x) {
      l = m + 1;
    } else {
      r = m - 1;
    }
  }
  return -1;
}
long long mindig(long long x) {
  long long ans = 9;
  long long t = x;
  while (x) {
    ans = min(ans, x % 10);
    x /= 10;
  }
  x = t;
  return ans;
}
long long maxdig(long long x) {
  long long ans = 0;
  long long t = x;
  while (x) {
    ans = max(ans, x % 10);
    x /= 10;
  }
  x = t;
  return ans;
}
void Fast() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  Fast();
  long long q;
  cin >> q;
  while (q--) {
    long long x;
    cin >> x;
    string s;
    cin >> s;
    long long n = s.length();
    ;
    long long ans = n;
    vector<char> v;
    for (long long i = 0; i < n; i++) v.push_back(s[i]);
    long long k = 0;
    while (1) {
      long long t = v.size();
      for (long long i = 0; i < v[k] - '1'; i++) {
        for (long long j = k + 1; j < t; j++) {
          v.push_back(v[j]);
        }
      }
      k++;
      if (v.size() >= x) break;
    }
    for (long long i = 0; i < x; i++) {
      ans = (ans + ((v[i] - '1') * (ans - i - 1)) % 1000000007 + 1000000007) %
            1000000007;
    }
    cout << ans % 1000000007 << "\n";
  }
}
