#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7FFFFFFF;
long long mod = 1000000007;
string s;
int x;
int t;
int main() {
  cin >> t;
  for (int q = 0; q < t; q++) {
    cin >> x >> s;
    int pos = 0;
    long long now = s.size();
    long long l = s.size();
    while (l < x + 10000 && pos < x) {
      pos++;
      int tmpl = l;
      int times = s[pos - 1] - '0';
      for (int k = 0; k < times - 1; k++)
        for (int i = pos; i < l; i++) {
          s.push_back(s[i]);
        }
      l = s.size();
    }
    while (pos < x) {
      pos++;
      now = l - pos;
      if (now < 0) {
        cout << l << endl;
        return 0;
      }
      l = (l + now * (s[pos - 1] - '0' - 1) % mod) % mod;
    }
    cout << l << endl;
  }
}
