#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    unsigned x;
    string s;
    cin >> x >> s;
    long long l = 0, size = s.length(), step = 0, max = 1e9 + 7;
    int p = x;
    while (p-- > 0) {
      ++l;
      int t = s[l - 1] - '0';
      step = ((t - 1) * ((size - l) % max)) % max;
      size = (size + step) % max;
      while (--t > 0 && s.length() < x) s = s + s.substr(l, string::npos);
    }
    cout << size << "\n";
  }
}
