#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    long long x;
    cin >> x;
    string str;
    cin >> str;
    long long pos = 1;
    while (str.size() < x) {
      long long rpt = str[pos - 1] - '0', tcnt = 0;
      string scon = str;
      scon.erase(0, pos);
      while (tcnt < rpt - 1) {
        str += scon;
        tcnt++;
      }
      pos++;
    }
    long long ans = (str.size()) % 1000000007;
    while (pos <= x) {
      long long rpt = str[pos - 1] - '0', tcnt = rpt;
      long long add = 0;
      while (tcnt--) {
        add = (add + ans - pos) % 1000000007;
      }
      ans = (pos + add) % 1000000007;
      pos++;
    }
    cout << ans << "\n";
  }
  return 0;
}
