#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    int x;
    cin >> x;
    string s;
    cin >> s;
    long long ans = s.length();
    for (int i = 0; i < x; ++i) {
      int n = s.length(), m = s[i] - '1';
      if (n <= x) {
        for (int j = 0; j < m; ++j) {
          s += s.substr(i + 1, n - 1 - i);
        }
      }
      ans = ((i + 1) + (ans - 1 - i) * (m + 1)) % 1000000007;
    }
    cout << (ans + 1000000007) % 1000000007 << "\n";
  }
  return 0;
}
