#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long x, i, j, k, ans = 0;
    string s;
    cin >> x >> s;
    vector<long long> res;
    for (auto h : s) res.push_back(h - '0');
    for (i = 1; x > res.size(); i++) {
      k = res[i - 1];
      long long d = res.size();
      k--;
      while (k--) {
        for (j = i; j < d; j++) res.push_back(res[j]);
      }
    }
    long long l = res.size() - i;
    for (; i <= x; i++) {
      l = (l * (res[i - 1]) - 1) % ((long long)1e9 + 7);
    }
    cout << (x + l + 1) % ((long long)1e9 + 7) << "\n";
  }
}
