#include <bits/stdc++.h>
using namespace std;
const long long M = 1000000007;
const long long N = 3e5 + 5;
signed main() {
  long long tc, i, j;
  long long n;
  cin >> tc;
  while (tc--) {
    long long x;
    cin >> x;
    string s;
    cin >> s;
    long long l = 1;
    string c;
    c = s.substr(l);
    s = s.substr(0, l);
    long long times = s[l - 1] - '0';
    while (times && s.length() <= x) {
      s += c;
      times--;
    }
    long long ans = s.length() % M;
    while (l != x) {
      l++;
      if (s.length() <= x) {
        c = s.substr(l);
        s = s.substr(0, l);
        long long tym = s[l - 1] - '0';
        while (tym && s.length() <= x) {
          s += c;
          tym--;
        }
      }
      long long sl = (s[l - 1] - '0');
      ans = (l % M + (sl * (ans - l)) % M) % M;
    }
    cout << ans % M << "\n";
  }
}
