#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
const long long INF = 1e18;
void rua() {
  string s, h;
  int x;
  cin >> x >> s;
  long long ans = 1ll * s.size();
  for (int i = 0; i < x; i++) {
    if (s.size() < x) {
      h = s.substr(i + 1);
      for (int j = 1; j < s[i] - '0'; j++) s += h;
    }
    ans = (ans + (ans - i - 1) * (s[i] - '0' - 1) + mod) % mod;
  }
  cout << ans % mod << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) rua();
  return 0;
}
