#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
map<int, int> order;
int main() {
  int T;
  cin >> T;
  while (T--) {
    long long x;
    cin >> x;
    string s;
    cin >> s;
    unsigned long long ans = s.size();
    long long n = s.size();
    for (long long i = 0; i < min(x, n); i++) {
      n = s.size();
      if (n == 1) {
        ans = 1;
        break;
      }
      if (x > n) {
        string z = s.substr(i + 1, n - (i + 1));
        unsigned long long temp = s[i] - '0';
        temp--;
        while (temp > 0 && x > s.size()) {
          s.append(z);
          temp--;
        }
      }
      unsigned long long q = s[i] - '0';
      ans = ((((ans - (i + 1)) * (q)) % MOD) + i + 1) % MOD;
    }
    cout << ans << "\n";
  }
  return 0;
}
