#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
string s;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int x;
    cin >> x >> s;
    long long len = s.size();
    for (long long i = 0; i < x; i++) {
      if (len < x) {
        int t = s[i] - '0' - 1;
        while (t-- and s.size() < x) {
          for (int j = i + 1; j < len and s.size() < x; j++) {
            s += s[j];
          }
        }
      }
      len = i + 1 + (long long)(s[i] - '0') * (len - i - 1) % mod;
    }
    cout << len % mod << "\n";
  }
  return 0;
}
