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