#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
const int mod = 1e9 + 7;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s, c, ts;
    int x;
    cin >> x;
    cin >> s;
    ts = s;
    long long siz = s.size(), f = 0;
    for (int i = 1; i <= x; i++) {
      if (f) {
        long long ch = s[i - 1] - '0', d = (siz - i + mod) % mod;
        siz = (siz + (ch - 1) * d) % mod;
        continue;
      }
      int ch = s[i - 1] - '0';
      if (ch == 1) {
        continue;
      }
      c = s.substr(i, s.size());
      for (int j = 1; j < ch; j++) s += c;
      siz = s.size();
      if (siz > x) f = 1;
    }
    cout << siz << endl;
  }
}
