#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long T;
long long MOD = 1e9 + 7;
long long safe_mod(long long x) { return ((x % MOD) + MOD) % MOD; }
void solve() {
  int X;
  cin >> X;
  string s;
  cin >> s;
  vector<int> nums;
  for (auto ch : s) {
    nums.push_back(ch - '0');
  }
  long long pos = 1;
  while (nums.size() <= (X + 100)) {
    int curr = nums[pos - 1];
    curr--;
    if (curr > 0) {
      vector<int> ins(nums.begin() + pos, nums.end());
      for (int i = 0; i < (curr); ++i) {
        nums.insert(nums.end(), begin(ins), end(ins));
      }
    }
    if (pos == X) {
      cout << nums.size() << endl;
      return;
    }
    pos++;
  }
  long long l = nums.size();
  while (pos <= X) {
    l += (safe_mod(nums[pos - 1] - 1) * safe_mod(l - pos)) % MOD;
    l %= MOD;
    pos += 1;
  }
  cout << l << endl;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int T;
  cin >> T;
  for (int i = 0; i < (T); ++i) {
    solve();
  }
}
