#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll fast_pow(ll a, ll b, ll m) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % m;
    a = (a * a) % m;
    b = b / 2;
  }
  return res;
}
template <typename T, typename U>
std::pair<T, U> operator-(const std::pair<T, U>& l, const std::pair<T, U>& r) {
  return {l.first - r.first, l.second - r.second};
}
template <typename T, typename U>
std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {
  return {l.first + r.first, l.second + r.second};
}
const ll maxn = 1e5 + 10LL;
const ll inf = 1e9 + 10LL;
const ll MOD = 1e9 + 7LL;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int x;
    cin >> x;
    string s;
    cin >> s;
    int l = 0;
    ll len = s.size();
    ll oldLen = s.size();
    while (s.size() < x) {
      string toAdd;
      int times = s[l] - '0';
      if (times != 1) toAdd = s.substr(l + 1, s.size() - l - 1);
      if (times == 3) {
        toAdd = toAdd + toAdd;
      }
      ll extraLen = (((times - 1) * (oldLen - l - 1)) % MOD + MOD) % MOD;
      len = (len + extraLen) % MOD;
      oldLen = len;
      if (times != 1) s += toAdd;
      l++;
    }
    while (l < x) {
      int times = s[l] - '0';
      ll extraLen =
          (((times - 1) * ((oldLen - l - 1)) % MOD) % MOD + MOD) % MOD;
      len = ((len + extraLen) % MOD + MOD) % MOD;
      oldLen = len % MOD;
      l++;
    }
    cout << len << endl;
  }
}
