#include <bits/stdc++.h>
using namespace std;
const long long MaxN = 3e5 + 100;
const long long LogN = 20;
const long long Inf = 2e15;
double eps = 1e-3;
long long md = 1e9 + 7;
long long dx[4] = {1, 0, 0, -1};
long long dy[4] = {0, 1, -1, 0};
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    long long x;
    cin >> x;
    string s;
    cin >> s;
    long long Ans = (s).size();
    deque<long long> c;
    for (int i = 0; i < (s).size(); i++) c.push_back(s[i] - '0');
    long long k = (c).size();
    bool f = 1;
    if (x <= (s).size()) f = 0;
    for (int i = 0; i < x; i++) {
      if (f) c.pop_front();
      k -= 1;
      Ans += k * (s[i] - '0' - 1);
      Ans %= md;
      if (f)
        for (int w = 0; w < s[i] - '0' - 1; w++) {
          for (int k = 0; k < (c).size() && f; k++) {
            s += c[k] + '0';
            if ((s).size() == x) {
              f = 0;
              break;
            }
          }
          if (f == 0) break;
        }
      k += k * (s[i] - '0' - 1);
      k %= md;
      long long w = (c).size();
      if (f)
        for (int k = 0; k < w * (s[i] - '1') && f; k++) c.push_back(c[k]);
    }
    cout << Ans << '\n';
  }
  return 0;
}
