#include <bits/stdc++.h>
using namespace std;
const long long int INFL = 1e18;
const int INFI = 1e9;
const long long int MOD = 1e9 + 7;
const int mod = 1e9 + 7;
long long int div_floor(const long long int &a, const long long int &b) {
  return a / b - (((a ^ b) < 0) and a % b);
}
long long int div_ceil(const long long int &a, const long long int &b) {
  return a / b + (((a ^ b) >= 0) and a % b);
}
long long int modpow(long long int a, long long int b, long long int m = MOD) {
  a %= m;
  long long int res = 1;
  while (b) {
    if (b & 1) res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
long long int bpow(long long int a, long long int b) {
  long long int res = 1;
  while (b) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long int modinv(long long int a, long long int m = MOD) {
  return modpow(a, m - 2, m);
}
void graph(vector<vector<int> > &adj, int m) {
  int x, y;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    adj[--x].push_back(--y);
    adj[y].push_back(x);
  }
}
void solve() {
  long long int x;
  cin >> x;
  string s;
  cin >> s;
  vector<char> str(3 * max(x, (long long int)s.size()) + 40);
  for (int i = 0; i < str.size(); i++) str[i] = '0';
  for (int i = 0; i < s.size(); i++) str[i] = s[i];
  long long int len = s.size();
  long long int lenstr = s.size();
  for (long long int i = 1; i <= x; i++) {
    long long int c = str[i - 1] - '0';
    if (lenstr < x) {
      if (c == 2)
        for (long long int j = i; j < lenstr; j++)
          str[lenstr + (j - i)] = str[j];
      else if (c == 3)
        for (long long int j = i; j < lenstr; j++)
          str[lenstr + (j - i)] = str[lenstr + (j - i) + (lenstr - i)] = str[j];
      lenstr = (lenstr + (lenstr - i) * (c - 1));
    }
    len = (len + MOD + (len - i + MOD) * (c - 1)) % MOD;
  }
  cout << len << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) solve();
}
