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