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