#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  cin >> TESTS;
  while (TESTS--) {
    long long x;
    cin >> x;
    string s;
    cin >> s;
    long long a[x + 1];
    for (long long int i = 1; i < min(x, (long long)s.size()) + 1; i++)
      a[i] = s[i - 1] - '0';
    long long i = s.size() + 1;
    long long l = 0;
    while (l <= x && i <= x) {
      l++;
      long long temp = i;
      for (long long int j = 0; j < a[l] - 1; j++) {
        for (long long int k = l + 1; k < temp; k++) {
          a[i] = a[k];
          i++;
          if (i > x) break;
        }
        if (i > x) break;
      }
    }
    long long ans = s.size();
    l = 0;
    while (l < x) {
      l++;
      ans = l + (ans - l) * a[l];
      ans %= 1000000007;
      ans = (ans + 1000000007) % 1000000007;
    }
    cout << ans << '\n';
  }
  return 0;
}
