#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int x;
    string s;
    long long int mod = 1000000007;
    cin >> x >> s;
    long long int res = s.size();
    vector<char> v;
    for (int i = 0; i < s.size(); i++) {
      v.push_back(s[i]);
    }
    for (int i = 1; i <= x; i++) {
      int n = v[i - 1] - '0';
      long long int d = res - i;
      long long int curr = res;
      res += (d * (n - 1)) % mod;
      n--;
      while (curr < x && n > 0) {
        curr += d;
        for (long long int j = 0; j < d && v.size() <= x; j++) {
          v.push_back(v[i + j]);
        }
        n--;
      }
    }
    cout << res % mod << "\n";
  }
}
