#include <bits/stdc++.h>
using namespace std;
void shikhar7s(long long int cas) {
  long long int x;
  cin >> x;
  string ss;
  cin >> ss;
  vector<char> s(ss.begin(), ss.end());
  long long int ls = (long long int)ss.length(), lc = 0, i, j, f = 0;
  for (i = 1; i <= x; i++) {
    if (!f) {
      vector<char> c(s.begin() + i, s.end());
      for (j = 0; j < (s[i - 1] - '0') - 1; j++) {
        s.insert(s.end(), c.begin(), c.end());
        if ((long long int)s.size() >= x) {
          f = 1;
          break;
        }
      }
    }
    lc = (ls - i + 1000000007) % 1000000007;
    ls = i;
    ls = (ls + (lc * (s[i - 1] - '0')) % 1000000007) % 1000000007;
  }
  cout << ls << "\n";
}
signed main() {
  std::ios_base::sync_with_stdio(false);
  long long int t = 1;
  cin >> t;
  long long int cas = 1;
  while (cas <= t) {
    shikhar7s(cas);
    cas++;
  }
  return 0;
}
