#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
int main(void) {
  int t;
  cin >> t;
  while (t--) {
    int x;
    string s;
    cin >> x >> s;
    ll len = s.length();
    vector<char> v(s.begin(), s.end());
    for (int i = 1; i <= x; i++) {
      int times = v[i - 1] - '0';
      if (v.size() < x) {
        vector<char> sub(v.begin() + i, v.end());
        for (int j = 1; j <= times - 1; j++) {
          v.insert(v.end(), sub.begin(), sub.end());
        }
      }
      len = (len + (len - i) * (times - 1)) % MOD;
    }
    cout << (len + MOD) % MOD << endl;
  }
  return 0;
}
