#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long N = (long long)1e9 + 7, M = 20;
long long i, j, x, y, z, m, n, k, l, r, f, mi, ans, x2, y2, ma, t, a[410000],
    b[410000], d[410000], dp[410000];
string s, s2;
vector<long long> v[410000], v2, v3;
string st(long long x) {
  string s3 = "";
  for (int i = x; i < s.size(); i++) {
    s3 += s[i];
  }
  return s3;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    cin >> n >> s;
    m = s.size();
    x = 0;
    ans = m;
    f = 0;
    for (i = 1; i <= n; i++) {
      x++;
      t = s[x - 1] - '0';
      if (!f && t != 1) {
        s2 = st(x);
        if (t == 2) s += s2;
        if (t == 3) s += s2 + s2;
      }
      ans = (ans + (ans - x + N) * (t - 1)) % N;
      if (ans > n) f = 1;
    }
    cout << ans << endl;
  }
}
