#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};
string s;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long x;
    cin >> x;
    cin >> s;
    long long n = s.size();
    int len = n;
    s = "#" + s;
    for (long long i = 1; i <= x; i++) {
      long long c = (n - i + 1000000007) % 1000000007;
      long long now = i + 1, to = n, val = s[i] - '0';
      while (val > 1) {
        for (int j = now; j <= to; j++) {
          if (len >= x) break;
          s.push_back(s[j]);
          len++;
        }
        val--;
      }
      val = s[i] - '0';
      n = (i + (c * val) % 1000000007) % 1000000007;
    }
    cout << n << endl;
  }
  return 0;
}
