#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = 5010;
int solve() {
  long long x;
  string str;
  cin >> x;
  cin >> str;
  long long ans = str.size();
  long long l = 0;
  while (l < x) {
    l++;
    if (str.size() < x) {
      string c = str.substr(l);
      for (long long i = 0; i < str[l - 1] - '0' - 1; i++) {
        str += c;
      }
    }
    ans = (ans + (ans - l) * (str[l - 1] - '0' - 1) % MOD + MOD) % MOD;
  }
  cout << ans << endl;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
