#include <bits/stdc++.h>
using namespace std;
int main() {
  int m = (int)1e9 + 7;
  long long t;
  cin >> t;
  while (t--) {
    long long x;
    cin >> x;
    string s;
    cin >> s;
    long long len = s.length();
    long long l = 1;
    long long ans = len;
    int mode1 = 1, mode2 = 0;
    while (1) {
      if (l == x + 1) {
        break;
      }
      if (mode1) {
        string s1 = s.substr(l);
        for (int i = 0; i < s[l - 1] - '0' - 1; i++) {
          s += s1;
          ans += s1.length();
          ans = ans % m;
        }
        if (s.length() >= x) {
          mode1 = 0;
          mode2 = 1;
        }
      } else {
        long long tobeappendedlength = (ans % m - l % m + m) % m;
        tobeappendedlength = tobeappendedlength % m;
        tobeappendedlength *= (s[l - 1] - '0' - 1) % m;
        tobeappendedlength = tobeappendedlength % m;
        ans += tobeappendedlength;
        ans = ans % m;
      }
      l++;
    }
    cout << ans << endl;
  }
}
