#include <bits/stdc++.h>
using namespace std;
int T;
int main() {
  cin >> T;
  while (T--) {
    string s;
    int x;
    cin >> x >> s;
    int pos = 0;
    long long lnt = (int)(s).size();
    while (pos < x) {
      ++pos;
      lnt %= 1000000007;
      if ((int)(s).size() <= x) {
        string c = s.substr(pos);
        long long toAdd = ((lnt - pos) % 1000000007 + 1000000007) % 1000000007;
        for (int i = 1; i < (s[pos - 1] - '0'); ++i) {
          s += c;
          lnt += toAdd;
          lnt %= 1000000007;
        }
      } else {
        long long toAdd = ((lnt - pos) % 1000000007 + 1000000007) % 1000000007;
        for (int i = 1; i < (s[pos - 1] - '0'); ++i) {
          lnt += toAdd;
          lnt %= 1000000007;
        }
      }
    }
    cout << lnt << endl;
  }
}
