#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const long long nn = 10 + 7;
const long long mod = 1e9 + 7;
void solve() {
  long long n, x;
  string s;
  cin >> x >> s;
  n = s.size();
  vector<char> arr(s.begin(), s.end());
  long long len = n;
  for (long long i = 1; i <= x; i++) {
    long long j = (long long)(arr[i - 1] - '1');
    if (arr.size() < x) {
      vector<char> temp(arr.begin() + i, arr.end());
      for (int k = 0; k < j; k++) {
        arr.insert(arr.end(), temp.begin(), temp.end());
      }
    }
    len = (len + (len - i) * j) % mod;
  }
  cout << (len % mod + mod) % mod << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int testcase = 1;
  cin >> testcase;
  for (int i = 0; i < testcase; i++) {
    solve();
  }
  return 0;
}
