#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    unsigned long long x;
    string s2;
    cin >> x >> s2;
    unsigned long long len = s2.size();
    vector<char> s;
    for (char i : s2) s.push_back(i);
    for (unsigned long long i = 1; i <= x; i++) {
      unsigned long long v = s[i - 1] - '1';
      if (s.size() < x) {
        vector<char> ss(s.begin() + i, s.end());
        for (unsigned long long it = 0; it < v; it++)
          s.insert(s.end(), ss.begin(), ss.end());
      }
      len = (len + (len - i) * v + 1000000007ll) % 1000000007ll;
    }
    cout << ((len + 1000000007ll) % 1000000007ll + 1000000007ll) % 1000000007ll
         << endl;
  }
  return 0;
}
