#include <bits/stdc++.h>
using namespace std;
const long long M = 1000000007;
const long long N = 1e6 + 5;
template <typename... T>
void bug(T... __VA_ARGS__) {
  ((cerr << __VA_ARGS__ << " "), ...);
}
signed main() {
  long long tc, i, j;
  long long n;
  cin >> tc;
  while (tc--) {
    long long x;
    cin >> x;
    string s;
    cin >> s;
    n = s.length();
    string c;
    for (long long l = 1; 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 += c;
          tym--;
        }
      }
      long long sl = (s[l - 1] - '0');
      n = (l + sl * (n - l)) % M;
    }
    cout << n << "\n";
  }
}
