#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MAX = 1e6 + 10;
const ll MOD = 1e9 + 7;
int main() {
  int t;
  cin >> t;
  short data[MAX];
  while (t--) {
    int x;
    cin >> x;
    string s;
    cin >> s;
    ll len = s.size();
    for (ll i = 0; i < len; ++i) {
      data[i] = s[i] - '0';
    }
    int l = 0;
    while (l < x && len < x) {
      ++l;
      int c = data[l - 1] - 1;
      ll diff = len - l;
      for (int i = 0; i < c; ++i) {
        for (ll j = 0; (l + j) < len && (j + len) < x; ++j) {
          data[len + j] = data[l + j];
        }
        len += diff;
      }
    }
    len = len % MOD;
    while (l < x) {
      ++l;
      int c = data[l - 1] - 1;
      ll diff = (len + MOD) - l;
      for (int i = 0; i < c; ++i) {
        len = (len + diff) % MOD;
      }
      if (len < 0) {
        exit(1);
      }
    }
    cout << len << "\n";
  }
  return 0;
}
