#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.substr(pos, str.size());
      while (tcnt < rpt - 1) {
        str += scon;
        tcnt++;
      }
      pos++;
    }
    long long ra = str.size() - pos;
    while (pos <= x) {
      long long tcnt = str[pos - 1] - '0';
      long long tsum = 0;
      while (tcnt--) {
        tsum = (tsum + ra) % 1000000007;
      }
      ra = tsum;
      ra--;
      pos++;
    }
    cout << (pos + ra) % 1000000007 << "\n";
  }
  return 0;
}
