#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
void rsolve() {
  int x;
  cin >> x;
  string s;
  cin >> s;
  vector<int> v;
  long long len = (int)(s).size();
  for (int i = 0; i < (int)(s).size(); i++) v.push_back(s[i] - '1');
  for (int i = 0; i < x; i++) {
    assert(i < (int)(v).size());
    int cp = v[i];
    long long lhs = i + 1;
    long long rhs = len - 1;
    len += cp * (MOD + rhs - lhs + 1);
    len %= MOD;
    for (int a = 0; a < cp; a++) {
      for (int b = lhs; b <= rhs && (int)(v).size() <= x; b++)
        v.push_back(v[b]);
    }
  }
  cout << len << "\n";
}
void solve() {
  int t;
  cin >> t;
  while (t--) rsolve();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
