#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 int ans = s.length();
    long long int l = 0;
    while (l != x) {
      l++;
      long long int n = s.length();
      int t = s[l - 1] - '0';
      for (int i = 0; i < t - 1; i++) {
        for (int j = l; j < n && s.length() <= x; j++) {
          s.push_back(s[j]);
        }
      }
      long long int c = (ans - l + 1000000007) % 1000000007;
      ans = (ans - c + 1000000007) % 1000000007;
      ans = (ans + (c * t) % 1000000007 + 1000000007) % 1000000007;
    }
    cout << ans << '\n';
  }
  return 0;
}
