#include <bits/stdc++.h>
using namespace std;
const int N = -1;
const int mod = 1e9 + 7;
int sum(int a, int b) {
  int c = (a + b);
  if (c >= mod) c -= mod;
  return c;
}
int mul(int a, int b) { return 1ll * a * b % mod; }
void solve() {
  int x;
  cin >> x;
  string s;
  cin >> s;
  int mx = 2 * x;
  int len = ((int)(s).size());
  for (int i = 1; i <= x; i++) {
    int cur = i;
    int rem = sum(len, mod - i);
    len = sum(len, mul(rem, (s[i - 1] - '1')));
    string t = "";
    if (((int)(s).size()) < mx && s[i - 1] != '1')
      t = s.substr(i, ((int)(s).size()) - i);
    while (((int)(s).size()) < mx && s[i - 1] != '1') {
      s += t;
      s[i - 1]--;
    }
  }
  cout << len << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
