#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MOD = 1e9 + 7;
int main() {
  int t;
  cin >> t;
  vector<int> data(1e6 + 10);
  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 (int 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;
      }
    }
    cout << len << "\n";
  }
  return 0;
}
