#include <bits/stdc++.h>
using namespace std;
istream& inp = cin;
template <typename T>
T divup(T a, T b) {
  if (b < 0) {
    a = -a;
    b = -b;
  }
  if (a < 0) return -((-a) / b);
  if ((a % b) == 0) return a / b;
  return 1 + a / b;
}
constexpr int M = 1000000007;
int32_t main() {
  int32_t ntests;
  assert(inp);
  inp >> ntests;
  for (int test = 0; test < ntests; ++test) {
    int x;
    string s;
    inp >> x >> s;
    int64_t total;
    for (int l = 1; 1; ++l) {
      int rep = s.at(l - 1) - '1';
      if (s.size() < x + 2) {
        int last = s.size() - 1;
        for (int i = 0; i < rep; ++i)
          for (int j = l; j <= last; ++j) s.push_back(s[j]);
        total = s.size();
      } else
        total = (total + rep * (total - l)) % M;
      if (l == x) break;
    }
    cout << total << "\n";
  }
  return 0;
}
