#include <bits/stdc++.h>
using namespace std;
long long t, x, ans, cursor;
string s;
bool ok;
void help() {
  if (s[cursor] != '1') {
    string snw;
    for (int i = cursor + 1; i < s.length(); ++i) snw.push_back(s[i]);
    if (s[cursor] == '2')
      s += snw;
    else if (s[cursor] == '3') {
      s += snw;
      s += snw;
    }
    if (s.length() > x) ok = false;
  }
  ans = s.length();
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    ok = true;
    ans = 0;
    cursor = 0;
    cin >> x;
    cin >> s;
    while (cursor < x) {
      if (ok)
        help();
      else
        ans = (ans + (s[cursor] - '1') * (ans - cursor - 1) + 1000000007) %
              1000000007;
      ++cursor;
    }
    cout << ans << '\n';
  }
}
