#include <bits/stdc++.h>
using namespace std;
using lli = long long;
using pii = pair<int, int>;
using pll = pair<lli, lli>;
template <typename T>
using Vector = vector<vector<T>>;
template <typename T>
using Prior = priority_queue<T>;
template <typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
const lli mod = 1E9 + 7;
void solve() {
  lli x, len;
  string s;
  cin >> x >> s;
  len = s.size();
  for (int i = 1; i <= x; ++i) {
    if (s.size() < x) {
      if (s[i - 1] == '2') s += s.substr(i, s.size() - i);
      if (s[i - 1] == '3')
        s += s.substr(i, s.size() - i) + s.substr(i, s.size() - i);
      len = s.size();
    } else {
      if (s[i - 1] == '2') len = (2 * len - i) % mod;
      if (s[i - 1] == '3') len = (3 * len - 2 * i) % mod;
    }
  }
  cout << (len < 0 ? len + mod : len) << "\n";
}
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
