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