#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long x, l = 0;
  string s;
  cin >> x;
  cin >> s;
  long long len = s.size();
  while (l != x) {
    long long ti = (s[l] - '0');
    l++;
    long long left = l;
    long long right = len - left;
    len = (left + (right * ti) % 1000000007) % 1000000007;
    long long cnt = (right * (ti - 1));
    while (cnt > 0 && s.size() <= x) {
      long long g = s.size();
      s += s[(int)(g - right)];
      cnt--;
    }
  }
  cout << len << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
