#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
void printV(vector<int> &S) {
  for (int s : S) {
    cout << s;
  }
  cout << endl;
}
void solve() {
  int x;
  cin >> x;
  string T;
  cin >> T;
  vector<int> S;
  for (int i = 0; i < (int)T.size(); i++) {
    S.push_back(T[i] - '0');
  }
  int l = 0;
  while (x > (int)S.size()) {
    int end = (int)S.size();
    for (int rp = 0; rp < S[l] - 1; rp++) {
      for (int i = l + 1; i < end; i++) {
        S.push_back(S[i]);
      }
    }
    l++;
  }
  long long len = (long long)S.size() - l - 1;
  for (int i = l; i < x; i++) {
    len *= S[i];
    len--;
    len %= MOD;
  }
  cout << (len + x + 1 + MOD) % MOD << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) solve();
}
