#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int x;
    cin >> x;
    string s;
    cin >> s;
    long long int n = s.size();
    long long int i = 0;
    while (s.size() < x) {
      long long int T = s[i] - '0';
      string p = s.substr(i + 1, s.size() - i - 1);
      if (T != 1)
        for (long long int j = 1; j < T; j++) {
          s = s + p;
        }
      i++;
    }
    for (i = 0; i < x; i++) {
      n = i + 1 + (n - i - 1) * (s[i] - '0');
      n %= 1000000007;
    }
    cout << n << endl;
  }
}
