#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vll = vector<ll>;
using graph = vector<vi>;
const int MAXN = 1e6 + 5;
const ll mod = 1e9 + 7;
ll sc[MAXN];
int main() {
  int x, n, t;
  cin >> t;
  string s;
  while (t--) {
    cin >> x;
    cin >> s;
    int n = s.size();
    for (int i = 0; i < n; ++i) {
      sc[i] = s[i] - '0';
    }
    int nxt = n;
    ll l = 0, ans = n, len = n;
    while (l < x) {
      ++l;
      ll c = ans - l;
      if (c < 0) c += mod;
      if (nxt < x) {
        int cnt = sc[l - 1];
        while (--cnt) {
          for (int i = l; i < len && nxt < x; ++i) {
            sc[nxt++] = sc[i];
          }
        }
      }
      if (nxt < x && len <= x) len = (l + (len - l) * sc[l - 1]);
      ans = (l + c * sc[l - 1]) % mod;
      if (ans < 0) ans += mod;
    }
    cout << ans << endl;
  }
}
